Wednesday, March 22, 2017

Bash: gawk - part II

# 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

No comments:

Post a Comment