LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 11-03-2010, 03:01 PM   #1
whocares357
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Rep: Reputation: Disabled
Ignoring Hidden Characters


I'm trying to look at a file and find 6 or more consecutive consonants (everything except a vowel). However I have a hidden $ character at the end of each line in the file. For some reason I can't reference to it in any of the pattern searching commands.

For example: grep '[^aeiouAEIOU$]\{6,\}' file| more

This command returns words that contain 5 consonants at the end (because it interprets the hidden $ as not a vowel). How can I make it ignore the hidden character? Or more specifically how do I refer to the hidden character in my pattern searches?

Thank you.

Last edited by whocares357; 11-03-2010 at 03:05 PM.
 
Old 11-03-2010, 03:09 PM   #2
HaroldWho
Member
 
Registered: Nov 2006
Location: southeastern PA
Distribution: Slackware
Posts: 130

Rep: Reputation: 23
The '$' needs to be escaped if it is to be treated as a character.

Code:
grep '[^aeiouAEIOU\$]\{6,\}' file| more
Note the '\$'

HTH
 
Old 11-03-2010, 03:12 PM   #3
whocares357
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by HaroldWho View Post
The '$' needs to be escaped if it is to be treated as a character.

Code:
grep '[^aeiouAEIOU\$]\{6,\}' file| more
Note the '\$'

HTH
This does not work either. It returns the same output as my original command.
 
Old 11-03-2010, 03:22 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
I think maybe you need to understand regular expressions a little bit more. The "hidden character", the dollar-sign, is not really there. In regular expressions, the dollar-sign indicates "end of the line" when making a match.
So, for example, if I use in a regex:

hello$

the regex would match a line where the word "hello" is the last word(characters) on the line. If I omit the "$" then the word "hello" can be matched anywhere in the line.

Now, using your first post for an example:
Code:
root@reactor: echo "bhbcxzA" | grep '[^aeiouAEIOU]\{6,\}'
bhbcxzA
root@reactor: echo "bhbcxzA" | grep '[^aeiouAEIOU]\{6,\}$'
root@reactor:
You see the match made in red text in the first case, because there is no "$" given in the grep regex. Therefore the match of 6-straight non-vowels can happen anywhere in the line.
In the second example, I have added a "$". Therefore there is no match, because there is a vowel at the end of the line, but my regex specifies that the run of consonants must be at the end of the line.

I hope this clarifies the issue of the hidden "$"

P.S. - I think there's still something wrong with the regex though - it doesn't match the vowels/consonants correctly for me.-
EDIT - sorry, I had a typo!

Last edited by GrapefruiTgirl; 11-03-2010 at 03:24 PM.
 
Old 11-03-2010, 03:33 PM   #5
whocares357
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by GrapefruiTgirl View Post
I think maybe you need to understand regular expressions a little bit more. The "hidden character", the dollar-sign, is not really there. In regular expressions, the dollar-sign indicates "end of the line" when making a match.
So, for example, if I use in a regex:

hello$

the regex would match a line where the word "hello" is the last word(characters) on the line. If I omit the "$" then the word "hello" can be matched anywhere in the line.

Now, using your first post for an example:
Code:
root@reactor: echo "bhbcxzA" | grep '[^aeiouAEIOU]\{6,\}'
bhbcxzA
root@reactor: echo "bhbcxzA" | grep '[^aeiouAEIOU]\{6,\}$'
root@reactor:
You see the match made in red text in the first case, because there is no "$" given in the grep regex. Therefore the match of 6-straight non-vowels can happen anywhere in the line.
In the second example, I have added a "$". Therefore there is no match, because there is a vowel at the end of the line, but my regex specifies that the run of consonants must be at the end of the line.

I hope this clarifies the issue of the hidden "$"

P.S. - I think there's still something wrong with the regex though - it doesn't match the vowels/consonants correctly for me.-
EDIT - sorry, I had a typo!
I understand this, but it doesn't really help me much. I want the 6 consecutive consonants to be ANYWHERE not just at the end of the line. If grep ignored the hidden characters I would not see the words with 5 consecutive consonants at the end of a line (because the pattern is looking for 6 not 5). That's why I assumed that grep was reading the hidden $ and considering it as a consonant, thus returning words that had 5 consecutive consonants at the end of a line.
 
Old 11-03-2010, 03:41 PM   #6
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Right, OK. Watch:
Code:
root@reactor: echo "AEIOUXYZXZZAEUIO" | grep '[^aeiouAEIOU]\{6,\}'
AEIOUXYZXZZAEUIO
root@reactor: echo "AEIOUXYZXZAEUIO" | grep '[^aeiouAEIOU]\{6,\}'
root@reactor:
You want to match 6 consecutive consonants, as shown above in example one. The 6 consonants are somewhere in the middle of the line. The second example only has 5 consonants, so is not matched.

Grep pays attention to any characters you tell it to pay attention to. However in this case, the "$" is not a character. It is merely a signifier of the "end of a line". If you don't care where in a line the match occurs, do not use a $. If you want the match to be at the end of the line only, then end your regex with a $.

Does that add clarity, or is there still something amiss?
 
  


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
LXer: Mastering Characters Sets in Linux (Weird Characters, part 2) LXer Syndicated Linux News 0 11-26-2009 12:30 AM
bash: mv hidden and not hidden files lupe Linux - General 4 06-22-2009 02:27 PM
Bluefish not showing hidden (?) non-ASCII characters? ta0kira Programming 3 04-12-2008 04:52 PM
How to modify the names of files and replace characters with other characters or symb peter88 Linux - General 2 12-10-2006 04:05 AM
ignoring special characters fredyk_ Linux - General 3 06-19-2006 10:50 AM


All times are GMT -5. The time now is 01:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration