BASH - how to press ENTER
Hi all,
I'm searching for a word in a text file with the command 'grep' and using 'grep -c' to print the number of matches on the screen. Afterwards I want to use a 'read' command, so that I can get the printed number. That is what I wrote in a script: nr_of_matches=0 grep -c -i -w "channel" <main.cpp read nr_of_matches Right now I have two problems: 1) the 'grep -c' command writes the number of matches and right afterwards it prints the number of matches (as expected), but it also gives an ENTER (as I didn't expect), even before the command 'read' is activated. 2) so the command 'read' doesn't let my script run to the end, because it stays waiting, so that something is writen and another ENTER is given. Does somebody has an idea how to solve this? |
How about this?
Code:
nr_of_matches=`grep -c -i -w "channel" <main.cpp` |
Perfect!!! :D
Things can be so easy once you know how to write them...Thanks a lot Berhanie! |
All times are GMT -5. The time now is 11:22 AM. |