Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i need to isolate a two word string seperated by one space. both words occur regularly in this file. all i need to do is isolate the lines that contain 'modify sent'. that is modify (space) sent. not just modify , and not just sent and not both words occuring in different places on one line, but just the two words together, - just 'modify sent'
I googled this and do not see much for a two word string seperated by a space bar - grep -w with quotes does not work. It seems easy but i can't figure it out. i searched for orderModified because it sometimes occurs with the string, but not always. i also made some vain attempts to modify the file (partial.eventlog vs evntlog.86453.partial)
two words seperated by a space bar, that is all i need to search for -
If it does not work for you, there has to be some other problem, you can try to do it in a smaller text file that you have created to see if it's a problem with the file or with the command.
The only problems I can think of right now are that the file has some "weird" characters or that you have an alias for grep/egrep which is making it behave in a different way.
You could try single quotes 'modify sent' - I'm not sure but may be handled differently to "
I've just noticed you've single quoted the last try, but escaped the second quote causing an error maybe
Last edited by andywebsdale; 08-22-2009 at 07:02 AM.
Reason: addition
You could try single quotes 'modify sent' - I'm not sure but may be handled differently to "
I've just noticed you've single quoted the last try, but escaped the second quote causing an error maybe
Bash does handle single quoted strings differently from double quoted strings.
Everything in single quotes is untouched by the shell. Thus when the shell is given '\modify |*sent\' on the grep command it gives \modify |*sent\ to grep (as a single word, with the spaces included). Dead simple, bash just copies each character after a single quote until it gets to another single quote.
Strings in double quotes are more complex. Here's from the GNU bash Reference "Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ‘\’, and, when history expansion is enabled, ‘!’. The characters ‘$’ and ‘`’ retain their special meaning within double quotes (see Shell Expansions). The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ‘!’ appearing in double quotes is escaped using a backslash. The backslash preceding the ‘!’ is not removed."
More complex, huh?!
If you don't quote strings then bash will look for a raft of things -- redirection, subshells, backgrounding, ...
So -- unless you need the power of double quoting, always use single quotes. KISS!
should work.
I agree with catkin, use single quotes unless you truly want interpolation etc.
If it doesn't work, consider if
1. you have invisible ctrl chars,
2. has file been uploaded from MSWin and NOT had line endings converted (dos2unix)
3. is it a case sensitivity issue?
4. is that phrase split with a newline in the middle, grep/egrep default to treating each line separately (std unix approach in many tools)
thank you for your posts. everyone here has been great.
the list above is a conglomeration of a few fruitless file searches.
lets just say that my organization has two matching engines - one department called me up and said 'where is 1/3 of my stuff' (note single quotes) and i was only picking up the other 2/3's. I spend alot of time digging through a 7 gig log.
anyhow it turns out that one of the channels on the circuit from our matching engine went down, and we did not have a record of certain transactions. all systems were up - just the one connection was down, networking reported it the next day.
grep with double or single quotes actually returned the correct output - just the info was wrong.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.