UNIX-1.5 Awk, Cut, Last, Wc Commands Video Tutorial


Make sure to subscribe to my channel for more videos on UNIX, Perl and SQL.
facebook: facebook.com/fuzicast
twitter: @fuzicast
youtube: youtube.com/yuejdesigner85

awk -F’|’ ‘BEGIN{ initialization } { code block } END{ finalization }’ – general syntax
default delimiter is space ‘ ‘
VAR=”value” – define a variable
print VAR – print a variable
NF is number of fields
$NF is value of last field
print “‘$EXTERNAL_VAR'” – double single $EXTERNAL_VAR single double
VAR~/pattern/ – pattern patching
VAR!~/pattern/ – does not match
FS returns value of field separator, same as -F
OFS returns output field separator
print $1,$2 is separated
NR returns line number
FILENAME returns current filename
awk -v var1=value1 – pre-assign values to variables in awk
awk -F, ‘conditions { code block }’ filename – condition must be right before code block

cut – get columns from file
cut -d, -f1-2 filename – print 1st to 2nd columns
cut -c1-5 filename – print first 5 characters
cut -d, -f2- filename – print from 2nd column to last column
cut -d, -f1,4,5 filename – print 1st, 4th and 5th column
cut -d, -f-3 filename – print from 1st to 3rd column
cut -d, -f1,3-5 filename – print 1st, 3rd to 5th column

wc – word count
wc -l – line count
wc -c – print number of bytes
wc – print number of newline, word and bytes
wc -m – character count
wc -w – word count

last – check login history
last -10 – show last 10 logins
last -F – show full login information

Advertisements