counting -| in Linux using grep

Reply

Join Date: Dec 2007
Posts: 8
Reputation: rolinski is an unknown quantity at this point 
Solved Threads: 0
rolinski rolinski is offline Offline
Newbie Poster

counting -| in Linux using grep

 
0
  #1
Apr 23rd, 2008
Hello!

I would like to know how can I tell to count the number of -| (minus followed by a pipe with no space) expressions in one line using grep in a given file.

I tried grep /\-|\ |/ | filename wc -l but this does not seem to work well.
Thank you for your answer.

Regards
/Rob
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 4
Reputation: riccio is an unknown quantity at this point 
Solved Threads: 1
riccio riccio is offline Offline
Newbie Poster

Re: counting -| in Linux using grep

 
0
  #2
Apr 29th, 2008
Try this:

grep "\- \|" * |wc -l

Bye
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: counting -| in Linux using grep

 
0
  #3
Jul 2nd, 2008
Originally Posted by rolinski View Post
Hello!

I would like to know how can I tell to count the number of -| (minus followed by a pipe with no space) expressions in one line using grep in a given file.

I tried grep /\-|\ |/ | filename wc -l but this does not seem to work well.
I think
echo "sdf -| qwe-|fgh-|fubar" | sed -e 's/-|/-|\n/g' a.a |grep -- "-|" |wc -l
should do and illustrate the trick. (Hint: try '--' before an argument that begins with a '-'; many GNU program understand '--' to mean 'end of options'.)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Getting Started and Choosing a Distro Forum
Thread Tools Search this Thread



Tag cloud for Getting Started and Choosing a Distro
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC