![]() |
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 |
| read and drop files | shantanuo | UNIX for Dummies Questions & Answers | 1 | 09-26-2008 03:00 AM |
| Drop a Column from a File | Raamc | UNIX for Dummies Questions & Answers | 4 | 01-09-2008 10:36 AM |
| Dynamic Drop down boxes | garric | Shell Programming and Scripting | 13 | 10-18-2007 11:54 AM |
| Drop records with non-numerics in field X | akxeman | Shell Programming and Scripting | 3 | 08-15-2007 12:55 AM |
| Drop Users | trfrye | UNIX for Dummies Questions & Answers | 2 | 08-31-2005 03:39 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Howdy all. I have some scripts that read a text file looking for a keyword, then returning all the text until another keyword and puts it into a new file. Problem is, sed returns the entire last line that contains the 2nd keyword, and I don't want it! Here's an example of the sed script line:
sed -n "/WX: /,/[0-2][0-9][0-5][0-9] TMU/P " 15.txt > test1.txt and here's what it returns: 1911 TMU WX: 1900 1/15-2300 1/15 PAZA SIGMET INDIA 9 FOR SEVERE HD TURBULENCE BELOW 100 WI AN AREA 20NM NW BGQ TO 40NM E BGQ TO 50NM E ENA TO 10NM W ENA TO 20NM NW BGQ. FWD: DCC,A11 2000 TMU Rick Bartow (IR) On duty position TMU The blue line is what I don't want. It is a separate entry that does not apply to the previous entry. I can't use grep, because it only gives me the first line of the entry, and each entry can vary in length, so I can't use a line count. These scripts are on Red Hat Enterprise 3 workstations, and I am not allowed to install anything that isn't already on them, so whatever scripting language is already there is all I can use. ![]() The next entry will always start with the date (4 digit), 4 spaces, then the word TMU. There is no other constant for the next entry. Is there any switch to sed or perhaps another command that will get the text I want but stop on the 2nd keyword, or some other way to strip the last line? I run the same script line multiple times with different beginning keywords so I can group them together into a single report. I should also mention that each file I am searching could have multiple entries with the same keyword. sed pulls them all in perfectly, except for the extra line from each entry. Any ideas??? Thanks!!! ![]() |
|
||||
|
Didn't work
Quote:
Code:
sed -n -e "/[0-2][0-9][0-5][0-9] TMU/d" -e "/WX: /,/[0-2][0-9][0-5][0-9] TMU/p " 15.txt > test1.txt , and the single quotes don't work here. Once I get something that works, I'll go upstairs and test it on the Linux box. If you think that might cause me a problem, I'll test it upstairs now. Thanks again! ![]() |
|
||||
|
Quote:
![]() |
|
|||||
Quote:
Quote:
Quote:
|
|
||||
|
Quote:
This worked in my tests. Basically you eliminate the four digits followed by the 'TMU' unless it follows that up with 'WX:' [edit] Well scratch that, "duh" moment for me, doesn't work if you have more than one entry to search for. It will eventually pull in another '1911 TMP WX:' line as the last line to the previous entry. Is there nothing in the actual last line (with the 'FWD:' in it) that you can key in on to make that the last line of your sed command? Otherwise I think but have not tested, that you could pipe the output from what I've done above through 'uniq -d' Last edited by rwuerth; 01-21-2009 at 02:01 PM.. Reason: Correction to my testing |
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|