Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-28-2009, 01:50 PM   #1
Registered: Oct 2009
Posts: 40

Rep: Reputation: 15
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:

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?
Old 10-28-2009, 01:55 PM   #2
Senior Member
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
How about this?
nr_of_matches=`grep -c -i -w "channel" <main.cpp`
Old 10-28-2009, 02:03 PM   #3
Registered: Oct 2009
Posts: 40

Original Poster
Rep: Reputation: 15


Things can be so easy once you know how to write them...Thanks a lot Berhanie!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i scan a character from keyboard without the user having to press enter rasika Programming 6 02-11-2010 09:54 PM
getline, why press enter twice?? blizunt7 Programming 3 09-06-2005 11:34 PM
"Disk boot failure. Enter system disk and press enter" Fear58 Linux - Hardware 3 06-25-2004 06:17 PM
Cant press enter for install B McHack Mandriva 4 01-22-2004 09:58 PM
press 'I' to enter interactive startup? xiaoxiao Linux - Software 3 04-06-2001 08:39 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:40 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration