18 Dec

Using M4 Command

This command takes an input file and substitutes strings inside it with the parameters passed, similar to substituting for variables. For example, here is an input file:

$ cat temp
The COLOR fox jumped over the TYPE fence.

Were you to substitute the strings “COLOR” by “brown” and “TYPE” by “broken”, you could use:

$ m4 -DCOLOR=brown -DTYPE=broken temp
The brown fox jumped over the broken fence.

Else, if you want to substitute “white” and “high” for the same:

$ m4 -DCOLOR=white -DTYPE=high temp
The white fox jumped over the high fence.

http://www.oracle.com/technology/pub/articles/advanced-linux-commands/part2.html

07 Mar

Changing separator with Perl

This will join all lines of a file together. Sometimes I have a list of something in a file, one line per item and want to convert it to a comma(colon,tab)-separated line (with no trailing separator of course) that can be used as a command-line parameter to some other tool.


perl -e '@_=; chomp(@_); print join(";",@_);' < data_file