Sed examples

From lippmann wiki
Revision as of 02:55, 7 June 2015 by Maarten (talk | contribs) (Created page with "==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 a...")
(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:

1
1
1
1