Sed examples
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:
1 1 1 1