How to extract last part of string in bash?

Simplest is echo “$A” | awk ‘{print $NF}’ Edit: explanation of how this works… awk breaks the input into different fields, using whitespace as the separator by default. Hardcoding 5 in place of NF prints out the 5th field in the input: echo “$A” | awk ‘{print $5}’ NF is a built-in awk variable that … Read more

How to get first n characters of each line in unix data file

With cut: $ cut -c-22 file 0000000000011999980001 0000000000021999980001 0000000000031999980001 0000000000041999980001 0000000000051999980001 0000000000061999980001 If I understand the second requirement you want to split the first 22 characters into two columns of length 10 and 12. sed is the best choice for this: $ sed -r ‘s/(.{10})(.{12}).*/\1 \2/’ file 0000000000 011999980001 0000000000 021999980001 0000000000 031999980001 0000000000 041999980001 … Read more

Grep output with multiple Colors?

You can cascade greps with different colors by specifying –color=always and using the regular expression ‘foo|$’ to pass all lines. For example: tail -f myfwlog | GREP_COLOR=’01;36′ egrep –color=always ‘ssh|$’ | GREP_COLOR=’01;31′ egrep -i –color=always ‘drop|deny|$’ If you want the entire line to be highlighted, update your regular expression accordingly: …. GREP_COLOR=’01;31′ egrep -i –color=always … Read more

How to UNCOMMENT a line that contains a specific string using Sed?

Yes, to comment line containing specific string with sed, simply do: sed -i ‘/<pattern>/s/^/#/g’ file And to uncomment it: sed -i ‘/<pattern>/s/^#//g’ file In your case: sed -i ‘/2001/s/^/#/g’ file (to comment out) sed -i ‘/2001/s/^#//g’ file (to uncomment) Option “g” at the end means global change. If you want to change only a single … Read more

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