# gawk 'BEGIN {print "The data3 File Contents:"}
{print $0}
> END {print "End of File"}' data3.txt
The data3 File Contents:
Line 1
Line 2
Line 3
End of File
===============================================
$ cat script4.gawk
BEGIN {
print "The latest list of users and shells"
print "UserID \t Shell"
print "------ \t------"
FS=":"
}
{
print $1 " \t " $7
}
END {
print "This concludes the listing"
}
$$ gawk -f script4.gawk /etc/passwd
The latest list of users and shells
UserID Shell
------ ------
root /bin/bash
bin /sbin/nologin
daemon /sbin/nologin
adm /sbin/nologin
lp /sbin/nologin
sync /bin/sync
shutdown /sbin/shutdown
halt /sbin/halt
mail /sbin/nologin
news
operator /sbin/nologin
Showing posts with label gawk. Show all posts
Showing posts with label gawk. Show all posts
Wednesday, March 22, 2017
bash: gawk - part I
$ gawk '{print $1}' data1.txt
little
under
besides
own
===============================================
$ gawk -F : -f ./script2.gawk /etc/passwd
$ cat script2.gawk
{print $1 "'s home directory is " $6}
===============================================
$ gawk -F : -f ./script3.gawk /etc/passwd
$ cat script3.gawk
{text="'s home directory is "
print $1 text $6
}
little
under
besides
own
===============================================
$ gawk -F : -f ./script2.gawk /etc/passwd
$ cat script2.gawk
{print $1 "'s home directory is " $6}
===============================================
$ gawk -F : -f ./script3.gawk /etc/passwd
$ cat script3.gawk
{text="'s home directory is "
print $1 text $6
}
Subscribe to:
Posts (Atom)