LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 07-07-2011, 06:32 PM   #1
eddyq
LQ Newbie
 
Registered: Nov 2009
Posts: 20

Rep: Reputation: Disabled
Using grep with the accent character present


I am filtering some output from gcc with grep. But if the output contains the accent character (`) I run into a problem. For example:

echo `xcvr_cmn_init' | grep xcvr

causes this:
>

Then I have to press ctrl/c to get back to a prompt.

(1) Can someone tell me what is going on? I suspect that it is trying to match up the accent with another accent. But my output is from gcc and there is no control over the fact that it uses an accent and a single quote around a name.
(2) Can someone tell me how to do the grep so it does not give the ">" prompt but instead locates "xcvr" in my example?
 
Old 07-07-2011, 07:23 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
The "accent" is not in the output; it's interpreted by the shell
as the start of a sub-command. What you really want to do for
testing with echo is:
Code:
echo '`xcvr_cmn_init' | grep xcvr
`xcvr_cmn_init
The above should explain both of your questions?



Cheers,
Tink
 
Old 07-08-2011, 03:24 PM   #3
eddyq
LQ Newbie
 
Registered: Nov 2009
Posts: 20

Original Poster
Rep: Reputation: Disabled
That will work because I can control the output of the echo. But I can't control the output of gcc.

So think of it this way. The command is:

gcc main.c | grep xcvr

Where the output of gcc is:

/this/that/the_other/main.c:512: undefined reference to `xcvr_cmn_init'

Last edited by eddyq; 07-08-2011 at 03:30 PM.
 
Old 07-08-2011, 03:57 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
If gcc outputs that the shell shouldn't interact with it.

One thing to note: most of gcc's output is on stderr,
so you probably want to do
gcc main.c |& grep xcvr

Last edited by Tinkster; 07-08-2011 at 04:02 PM.
 
Old 07-08-2011, 04:46 PM   #5
eddyq
LQ Newbie
 
Registered: Nov 2009
Posts: 20

Original Poster
Rep: Reputation: Disabled
Ok, I got it working. I think I tried to oversimplify my original post because my real case is very involved. When I tried to use the echo command that probably set me back.
 
  


Reply



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
[SOLVED] special character in string variable and grep ted_chou12 Linux - Newbie 4 04-11-2011 07:59 AM
[SOLVED] Grep until certain character or pattern appears ohijames Programming 7 06-28-2010 08:38 PM
grep '^[^1]' h.txt (what does the " ' " character indicate babu198649 Linux - Newbie 4 12-29-2007 10:32 AM
ndiswrapper shows 'driver present, hardware present' but no wlan0 0x12d3 Linux - Wireless Networking 2 05-11-2007 07:43 PM
ndiswrapper - driver present:harware present but no connection esteeven Linux - Wireless Networking 2 12-26-2004 04:06 PM

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

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

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