![]() |
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 |
| How to print only lines in between two strings using awk | jisha | Shell Programming and Scripting | 4 | 01-11-2008 04:13 AM |
| Print to ps2pdf print queue | Sean_69 | SUN Solaris | 2 | 10-22-2007 12:00 PM |
| Print Problem in UNIX. Need to know the option to specify the print paper size | ukarthik | HP-UX | 1 | 06-07-2007 10:35 AM |
| How do I get awk to print a " in it's print part? | LordJezo | Shell Programming and Scripting | 2 | 06-27-2006 10:16 PM |
| How to concatenate two strings or several strings into one string in B-shell? | fontana | Shell Programming and Scripting | 2 | 08-26-2005 12:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Print all between 2 strings
Hi All,
I'm working on a large file and need to extract all data between 2 strings. I have seen many good solutions to threads almost like my problem but none that quite fit. This is all very new to me so any ideas would be really appreciated! (attempted to read sed and awk tutorials but got a headache trying to take it all in!) Sample of data... DEF on DEF off ABC on DEF on DEF off GHI on DEF on ABC off ABC on ABC off DEF off etc..etc There are duplications of the main strings I need to include in the output file, so I need to capture the first instance 'ABC on' and the last instance of 'ABC off'. I need to extract all the data to resemble the output below.. ABC on (first occurence) DEF on DEF off GHI on DEF on ABC off ABC on ABC off (last occurence) Thanks In Advance. Soots |
|
||||
|
Thanks for the response...for some reason I get the following error messages:
awk: syntax error near line1 awk: bailing out near line 1 I've check the syntax of your script on my machine, it is as per your posting. Any thoughts appreciated. Regards Soots |
|
||||
|
Quote:
Regards |
|
||||
|
Did as suggested, used /usr/xpg4/bin/awk. Error messages went away but output did not materialise. The strings I'm using as begin and end placeholders are within a .dat file called machinelog.dat that looks similar to this
6/1/09 23:22:00 Machine1 Initialising : Initialising 6/1/09 23:22:01 Machine1 DEF on : system on 6/1/09 23:22:04 Machine1 ABC on : system on 6/1/09 23:22:05 Machine1 DEF on : system on 6/1/09 23:22:06 Machine1 ABC off : system off 6/1/09 23:22:07 Machine1 DEF off : system off 6/1/09 23:22:22 Machine1 ABC on : system on 6/1/09 23:22:25 Machine1 ABC off : system off 6/1/09 23:22:38 Machine1 ABC on : system on 6/1/09 23:23:07 Machine1 DEF on : system on 6/1/09 23:23:09 Machine1 ABC on : system on 6/1/09 23:23:15 Machine1 DEF on : system on 6/1/09 23:23:16 Machine1 ABC off : system failure 6/1/09 23:23:18 Machine1 DEF off : system off 6/1/09 23:23:22 Machine1 ABC on : system on 6/1/09 23:23:25 Machine1 ABC off : system failure 6/1/09 23:23:38 Machine1 ABC on : system on 6/1/09 23:24:07 Machine1 DEF on : system on and I was hoping to capture everything between the first ABC on and the last system failure and put it into a new file called machinelogmain.dat, like below: 6/1/09 23:22:04 Machine1 ABC on : system on 6/1/09 23:22:05 Machine1 DEF on : system on 6/1/09 23:22:06 Machine1 ABC off : system off 6/1/09 23:22:07 Machine1 DEF off : system off 6/1/09 23:23:22 Machine1 ABC on : system on 6/1/09 23:23:25 Machine1 ABC off : system off 6/1/09 23:23:38 Machine1 ABC on : system on 6/1/09 23:22:07 Machine1 DEF on : system on 6/1/09 23:22:00 Machine1 ABC on : system on 6/1/09 23:22:01 Machine1 DEF on : system on 6/1/09 23:22:04 Machine1 ABC off : system failure 6/1/09 23:22:07 Machine1 DEF off : system off 6/1/09 23:23:22 Machine1 ABC on : system on 6/1/09 23:23:25 Machine1 ABC off : system failure I tried to substitute the ABC on/ABC off etc but not much joy! Does your script format still apply or will it require a change? Thanks for your patience. Regards soots |
![]() |
| Bookmarks |
| Tags |
| save data between two strings |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|