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!
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.
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 -
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!
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.