Difference between revisions of "Sed examples"

From lippmann wiki
Jump to: navigation, search
(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...")
 
 
Line 4: Line 4:
  
 
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.  
 
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:
+
Below is the output (piped to head -5 to limit output)
  
  1
+
  root@sdprod:[~] #sed -e 's/[^a]//g' replace | awk '{ print length }' |head -5
  1
+
  2
  1
+
  5
  1
+
  5
 +
5
 +
3

Latest revision as of 02:57, 7 June 2015

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