Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • so In my case, the combination of the both sed + awk could be done using awk -i inplace '!/^[#@]/{printf("%.1f\n",$2*10)}' file.xvg ? assuming that I would like to edit the existing file and not create new one Commented Dec 17, 2020 at 16:01
  • Yes, with GNU Awk. If not with GNU awk, you could always redirect to a new file and then overwrite the old file by the new one (it is the standard procedure). Or use sponge from moreutils package. Commented Dec 17, 2020 at 16:03
  • I've just tried and it works very well! could you please specify what is the difference between GNU and non-GNU Awk ? I am using MacOCS writting scripts in bash and always use commands like sed -i '' -e '/^[#@]/d' to edit instantly filles .. thanks again Commented Dec 17, 2020 at 16:29
  • @HotJAMS: macOS doesn't ship with GNU awk; it ships with an old-ish BSD version of awk. Apple's latest upgrade for awk was in Oct, 2007 according to this document.. OTOH, GNU awk is currently maintained. The good news is you don't have to use Apple's antique awk - MacPorts has a recent gawk available. You can then wonder why the world's largest corporation ships 13-year-old software with their pricey computers. Commented Dec 17, 2020 at 23:12
  • @HotJAMS: Oh - I failed to mention the documentation - very important stuff for users! I learn best by example, and GNU awk has documentation to support learn-by-example. Apple has man awk - not overly helpful. Finally - see this Commented Dec 17, 2020 at 23:33