Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

utilitydefault delimiterhow to changeexample
cuttab-d or --delimiter optioncut -d ':' -f 1 /etc/passwd
sortwhitespace
(one ore more spaces or tabs tabs)
-t or --field-separator optionsort -t ':' -k1,1 /etc/passwd
awkwhitespacespaces
(one ore more spaces or tabs)
for both input and output
  • FS (input field separator) and/or OFS (output field separator) variable in BEGIN{ } block
  • -F or --field-separator option

cat sampleinfo.txt | awk 'BEGIN{ FS=OFS="\t" }{print $1,$3}'

cat sampleinfo.txt | awk -F "\t" '{ print $1,$3 }'


joinone or more spaces-t option
join -t $'\t' -j 2 file1 file12 
perlwhitespace
(one ore more spaces or tabs)
when auto-splitting input with -a
-F'/<pattern>/' optioncat sampleinfo.txt | perl -F'/\t/' -ane 'print "$F[0]\t$F[2]\n";'
readwhitespace
(one ore more spaces or tabs
IFS= optionsee example above

...

  • Default field separators
    • Tab is the default field separator forĀ cut
    • whitespace spaces (one or more spaces) is the default field separator for awk
  • Re-ordering
    • cut cannot re-order fields; awk can, based on the order you specify
  • awk is a full-featured programming language while cut is just a single-purpose utility.

When to use these programs is partly a matter of taste. I often use either cut or awk to deal with field-oriented data. Even though awk is a full-featured programming language, I find its pattern matching and text processing facilities awkward (pun intended), and so prefer perl for complicated text manipulation.

...