Unix Commands-1 (1)
Unix Commands-1 (1)
AWK Uses
awk '{print $2}' print second coloum
awk '{print $2 $4}' print second coloum and fourth coloum
awk '{print $NF}' print only last line
awk '{print $NR}' just only give number
awk '{print NR,$0}'
awk'{for(i=1;i<=NF;i++)print $i}' printing each field in row in new line
awk 'BEGIN {print"hi"}{print $1} BEGIN keyword used to before parsing all the lines
awk'{print$1}END{print"bye"}' END key word is used after parsing all the lines
awk '{sum+=$1}END{print sum}' adding values
awk 'NF>=4' print all lines having greater than four fields
awk'/rdt_done/{print $1}' sample.rpt awk can serve the purpose of grep
SED Uses
sed 's/foo/bar/' substitute (find and replace )the first occurrence of "foo" with "bar" on each line
sed 's/foo/bar/2' substitute (find and replace) the second occurrence of ''foo with "bar" on each line .
sed 's/foo/bar/g' substitute (find and replace ) all occurrence of "foo" with "bar" on each line
sed '/baz/s/foo/bar/g' Substitute all occurrences of "foo" with "bar" on all lines that contain "baz".
sed '/baz/!s/foo/bar/g' Substitute all occurrences of "foo" with "bar" on all lines that DO NOT contain "baz".
sed 's/scarlet\|ruby\|puce/red/g' replacing multiple patterns with one pattern
sed 's/^[ \t]*//;s/[ \t]*$//' Delete both leading and trailing whitespace from each line.
sed -e 's/^[ \t]*//’ -e ‘s/[ \t]*$//' Delete both leading and trailing whitespace from each line.
sed '/PATTERN-1/,/PATTERN-2/d' delete all the lines between 2 patterns
sed -i -e '/PATTERN-1/,/PATTERN-2/{s/^/#/g}' between 2 patterns using search and replace
grep Uses
grep ‘pattern' filename
grep 'Design' -A1 timing.rpt returns pattern match and 1 line after the pattern
grep 'Design' -B1 timing.rpt returns pattern match and 1 line before the pattern
grep 'Design' -C1 timing.rpt returns pattern match and 1 line after the pattern & 1 line before the pattern
grep 'Design\|Version' -A1 timing.rpt
grep -E 'Design|Version' -A1 timing.rpt egrep 'Design\|Version' -A1 timing.rpt
egrep 'Design\|Version' -A1 timing.rpt
grep -i 'design' -A1 timing.rpt ignore case
grep -v 'Startpoint' timing.rpt return all lines except match
grep -o 'Startpoint' timing.rpt return only matching pattern excluding lines
grep -l 'Startpoint' ./* return file names having pattern
grep -c 'Startpoint' timing.rpt return total count of matches
grep --color 'Startpoint' timing.rpt colouring the matching pattern
grep -n 'Startpoint' timing.rpt return with line numbers
grep -m2 'Startpoint' timing.rpt stop search after certain occurance
grep '[[:alnum:]]' timing.rpt all alphanumeric characters
Find Uses