Home > Linux, Redhat > Awk notes

Awk notes

Here’s a useful snippit/shell script that can tell you quite a bit on the power of awk:

#!/bin/bash
awk -F”:” ‘ ‘
BEGIN (
print “=============================================”
printf “%-8s %-3s %-3s %-15s %-15s\n”,”User”,”UID”,”GID”,”HOME”,”SHELL”
print “=============================================”
)
NR==1,NR==10( printf “%-8s %3d %3d %-15s %-15s\n”,$1,$3,$4,$6,$7 ) ‘ /etc/passwd
### End of script

BEGIN = Header info
%-8s = max width of field/string to pring (8s), left justified (-)
NR==1,NR==10 = Rows between 1-10
%3d = minimum 3 digits to print, right justified

Categories: Linux, Redhat
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: