-->

Tuesday, October 23, 2012

awk pills



# print last column 
awk '{print $NF}'




# divide by two the total number of lines of a file (for splitting  lists of files )

wc -l all.jpgl | awk '{$1/=2; printf "%.0f",$0}'






# Print lines longer than 72 characters:
  awk 'length > 72' file
    
# Print length of string in 2nd column
  awk '{print length($2)}' file


# Add up first column, print sum and average:
       { s += $1 }
  END  { print "sum is", s, " average is", s/NR }


# Print fields in reverse order:
  awk '{ for (i = NF; i > 0; --i) print $i }' file


# Print the last line
      {line = $0}
  END {print line}

# Print column 3 if column 1 > column 2:
  awk '$1 > $2 {print $3}' file
     

# Print line if column 3 > column 2:
  awk '$3 > $2' file


# Count number of lines where col 3 > col 1
  awk '$3 > $1 {print i + "1"; i++}' file


# Print sequence number and then column 1 of file:
  awk '{print NR, $1}' file


# Print every line after erasing the 2nd field
  awk '{$2 = ""; print}' file


# Print hi 28 times
  yes | head -28 | awk '{ print "hi" }'

# remove duplicate lines

awk '!x[$0]++'

No comments:

Post a Comment