How can I pass variables from awk to a shell command?
you are close. you have to concatenate the command line with awk variables: awk ‘{system(“wc “$1)}’ myfile
you are close. you have to concatenate the command line with awk variables: awk ‘{system(“wc “$1)}’ myfile
$ cat file | awk ‘END{print}’ Originally answered by Ventero
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
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
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
In awk: awk ‘$2 == “LINUX” { print $0 }’ test.txt See awk by Example for a good intro to awk. In sed: sed -n -e ‘/^[0-9][0-9]* LINUX/p’ test.txt See sed by Example for a good intro to sed.
svn pg -R svn:ignore . …with pg being a shorthand notation for propget, so this is equal to… svn propget -R svn:ignore .
Try doing this : awk ‘{print substr($0, 1, length($0)-1)}’ file.txt This is more generic than just removing the final comma but any last character If you’d want to only remove the last comma with awk : awk ‘{gsub(/,$/,””); print}’ file.txt
You could also do something like this (provided you have lynx installed)… Lynx versions < 2.8.8 lynx -dump -listonly my.html Lynx versions >= 2.8.8 (courtesy of @condit) lynx -dump -hiddenlinks=listonly my.html
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