Awk: Difference between revisions

From Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 8: Line 8:
<pre>
<pre>
echo "a=b=c" | awk -F= '{print $3}'  # selects "c"
echo "a=b=c" | awk -F= '{print $3}'  # selects "c"
</pre>
Duplicate entries in the passwd file?
<pre>
awk -F: '{print $1}' /etc/passwd | sort -u | wc -l > temp1
awk -F: '{print $1}' /etc/passwd | sort    | wc -l > temp2
diff temp1 temp2
rm temp1 temp2
</pre>
</pre>

Latest revision as of 17:47, 19 April 2018

Pick out the fourth token:

mac=`/sbin/arp -a $ip | awk '{print $4}'`

Separate by = instead of whitespace:

echo "a=b=c" | awk -F= '{print $3}'  # selects "c"

Duplicate entries in the passwd file?

awk -F: '{print $1}' /etc/passwd | sort -u | wc -l > temp1
awk -F: '{print $1}' /etc/passwd | sort    | wc -l > temp2
diff temp1 temp2
rm temp1 temp2