Sed examples

From lippmann wiki
Jump to: navigation, 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