LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-28-2009, 12:50 PM   #1
carolflb
Member
 
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:

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

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

Original Poster
Rep: Reputation: 15
Talking

Perfect!!!

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


Reply


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 08:54 PM
getline, why press enter twice?? blizunt7 Programming 3 09-06-2005 10:34 PM
"Disk boot failure. Enter system disk and press enter" Fear58 Linux - Hardware 3 06-25-2004 05:17 PM
Cant press enter for install B McHack Mandriva 4 01-22-2004 08:58 PM
press 'I' to enter interactive startup? xiaoxiao Linux - Software 3 04-06-2001 07:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:27 AM.

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