Sed examples

From lippmann wiki
Revision as of 02:57, 7 June 2015 by Maarten (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

count the number of a specific character in each line

sed 's/[^a]//g' file | awk '{ print length }'

This removes all characters in each line outside of 'a' (a used as an example). Then this is piped to awk, and the number of characters in each line is counted and listed on a per line basis. Below is the output (piped to head -5 to limit output)

root@sdprod:[~] #sed -e 's/[^a]//g' replace | awk '{ print length }' |head -5
2
5
5
5
3