![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Text formatting question | aliaa2a | Shell Programming and Scripting | 7 | 05-24-2008 07:27 AM |
| Question about sed. Inserting text in field? | pcrs | Shell Programming and Scripting | 2 | 02-12-2007 02:56 PM |
| searching text question | BG_JrAdmin | UNIX for Dummies Questions & Answers | 4 | 05-29-2005 08:52 AM |
| Text parsing question | 98_1LE | UNIX for Dummies Questions & Answers | 3 | 03-24-2002 11:04 AM |
| Filtering text from a string | Cozmic | UNIX for Dummies Questions & Answers | 5 | 03-15-2001 11:18 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I want to remove everything from a file but the word following the search word.
Example: crap crap crap crap SearchWord WordToKeep crap crap crap How would I do this with say awk or grep? Thank you! |
|
||||
|
Sorry to correct you, vino, but your code will work only in most cases, not in all: if the WordToKeep is the last word in the line it will fail because you require a space after it.
On the first line your code will work, on the second it will fail: Code:
"crap crap searchword wordtokeep crap" "crap crap searchword wordtokeep" Code:
"crap crap searchword wordtokeep, crap" I therefore suggest the following enhancement to your code (<spc> and <tab> are characters, only encoded here for readability): Code:
sed -e "s/.*SearchWord \([^<spc><tab>;,.!?":][^<spc><tab>;,.!?":]*\)/\1/g" file |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|