Home
Up

 

SED tutorial

http://pegasus.rutgers.edu/~elflord/unix/sed.html

 

awk ls -l *.cgm | awk '
{ total += $7 }
{mbtotal = total/1048576}
END
{ printf ("Size =%.2f Mbytes\n", mbtotal) }'
  Total file sizes from ls -l and display as MB
awk ls -l *.cgm | awk '
{ total += $7 }
END
{ pritf ("Size =%d\n", total) }'
  Total file sizes from ls -l
awk cat filename | awk '
{ print $0, getline }' > filename.odd
cat filename | awk '
{ getline first, print $first }' > filename.even
  Separate odd lines and even lines
awk cat filename | awk '
{sum += $1, ++count }
END
{average = sum / count, print average} '
field 1 should be numbers ($1) Average a list of number
awk cat file | awk '
{ for (i=10;i<=NF;i++) printf $i " "}
END
{print}'
i= column number to print from print columns X to end of line
awk awk 'substr ($0,n,1) == "c" ' filename c= character to search for n= column to seach in Find a particular chatacter in a certain column
awk .... I awk '{ print length ($1)}'   How many characters in a field
awk awk '{ print $NF }'   Print last field
awk cat passwd I awk -F":" '
{ q=NF -1 } { print $q }'
good for getting home directory as password
and GCOS can have delimiters in
print last but one field
 

© Andrew Marshallsay 2008