suppose i have this line
abs|der|gt|dftnrk|dtre
i want to count the number of "|" in this line..
how can i do that.
plz help:confused:
suppose i have this line
abs|der|gt|dftnrk|dtre
i want to count the number of "|" in this line..
how can i do that.
plz help:confused:
what have you tried?
i tried with grep..
grep -c "|" filename
but it is giving me the count of only the line number in which is pattern is present..i wnt to count the number of occurences of this pattern in a file
echo "abs|der|gt|dftnrk|dtre" | sed 's/|/
>&/g' | grep "|" |wc -l
echo "abs|der|gt|dftnrk|dtre" | awk '{ print gsub("\|","~",$0) }'
You can also use the '-o' flag for grep and then pipe it to wc
-bash-3.2$ echo "abs|der|gt|dftnrk|dtre" | grep -o "|" | wc -l
4
echo "|abs|der|gt|dftnrk|dtre|" | awk -F"|" '{print NF-1}'
thanx the last solution is working
Or delete every character except pipe, and count them.
echo "|abs|der|gt|dftnrk|dtre|" |tr -cd '|'|wc -c
but when i am trying it with a file then it is giving the separate output
like
5
5
5
5
5.
since the file contains five line and 5 "|" in each line
please help
i want total of the pipes in whole file:confused:
thanks i got it....