Awk to skip the blank lines

There are two approaches you can try to filter out lines: awk ‘NF’ data.txt and awk ‘length’ data.txt Just put these at the start of your command, i.e., awk -v variable=$bashvariable ‘NF { print variable … }’ myinfile or awk -v variable=$bashvariable ‘length { print variable … }’ myinfile Both of these act as gatekeepers/if-statements. … Read more

Sed : print all lines after match

To print all lines after, and including, the first match: $ echo -ne ‘apple\nbanana\ncherry\n’ | sed -ne ‘/banana/,$ p’ banana cherry To print all lines after, and NOT including, the first match: $ echo -ne ‘apple\nbanana\ncherry\n’ | sed -e ‘1,/banana/ d’ cherry Filtering lines when pattern matches between “text=” and “status=” can be done with … Read more

binary sed replacement

bbe is a “sed for binary files”, and should work more efficiently for large binary files than hexdumping/reconstructing. An example of its use: $ bbe -e ‘s/original/replaced/’ infile > outfile Further information on the man page.

sed search and replace strings containing / [duplicate]

Don’t escape the backslashes; you’ll confuse yourself. Use a different symbol after the s command that doesn’t appear in the text (I’m using % in the example below): line_old=’myparam /path/to/a argB=/path/to/B xo’ line_new=’myparam /path/to/c argB=/path/to/D xo’ sed -i “s%$line_old%$line_new%g” /etc/myconfig Also, enclose the whole string in double quotes; using single quotes means that sed sees … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)