I forgot a lot of my command line. I am doing cat file | grep "error" and i would like it to show everything to the right of G:/ including G:/ if possible. I figure its an awk command but i dont know what. I tried awk '{print $8+}' but + does not work like i hoped and guessed.

link|improve this question

55% accept rate
What's the file layout? – John T May 17 '10 at 11:23
1  
Hmm, G:/ -- is that Cygwin on Windows? – nik May 17 '10 at 11:45
feedback

2 Answers

up vote 1 down vote accepted

awk '/G:/{ print substr($0, match($0, /G:/)); }' file

link|improve this answer
That prints the full line. Also i can see you havent tested as there is two ) which gives it an error. The sed solution above works. – acidzombie24 May 17 '10 at 11:58
Did you run it? I did. It works just fine based on based on your description of the file (which I understood to be "stuff...G:/more stuff more stuff"). The two parens are required; one to close match(), one to close substr(). match() finds the string you wanted to print; substr() prints from where that string begins to the end of the line. Also: you're welcome. – JRobert May 17 '10 at 12:48
Oh sorry. I did run it but i did it wrong. Which explains why i had the syntax error. oops, sorry. This works great. – acidzombie24 May 17 '10 at 14:52
I'm glad to know it worked for you. And I appreciate the follow up - thank you. – JRobert May 17 '10 at 15:55
feedback

Try:

cat file | sed "s/.*\(G:\/\)/\1/"

That will remove everything before G:/. Be aware that if you have multiple G:/ entries it will match the very last entry. If you're only working with a single file instead do:

sed "s/.*\(G:\/\)/\1/" file
link|improve this answer
Wouldn't you want to catch the text after the G:/ to the end of line? You are missing a couple of chars in the pattern... However, the leading .* in the pattern is probably not going to let it work as expected even with that fix. – nik May 17 '10 at 11:48
I had to do sed "s/\(.*\)\(G:.*\)/\2/" – acidzombie24 May 17 '10 at 11:55
@acidzombie24: You probably don't need to capture the first group. This will probably work: s/.*\(G:.*\)/\1/ (the parentheses need to be escaped unless you are using the -r option or your version of sed does that for you). – Dennis Williamson May 17 '10 at 13:50
I copied the results here wrong. What happened on my side was since the first group wasnt capture they werent getting replaced/they were still showing up in stdout. – acidzombie24 May 17 '10 at 14:53
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.