![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pulling multiple lines of text | DumDum | Shell Programming and Scripting | 2 | 03-10-2008 09:15 AM |
| Pulling a file off a backup tape | rocker40 | UNIX for Dummies Questions & Answers | 14 | 10-12-2007 08:37 AM |
| Pulling data and following lines from file | MizzGail | Shell Programming and Scripting | 2 | 01-31-2006 12:13 PM |
| pulling a column from a file in ksh | dangral | Shell Programming and Scripting | 8 | 01-13-2003 01:10 PM |
| Pulling out fields from a file | Saz | UNIX for Advanced & Expert Users | 2 | 09-30-2001 12:31 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
pulling the following line from a file
I have return files from a process that has then original input record followed on the next line by a response record..either AA,........... for accepted or EE,.......... for errored.
i.e 11,new,123 AA,accepted 12,exist,443 EE,rejected 13,old,223 AA,accepted I want to write a small script that will return the row and it's response to a separate file. I.e. I tell the script I want the records that start 11 and their responses and I get the first two lines above. I can do the pattern matching etc to get the first line - but I am having trouble getting the second line to come back too.
__________________
Pete |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Could you use the -n option of grep to get the line numbers & use awk with {FS=":"} {print $1} to chop them out into a temporary file.
You can then run down the input file again with this file of line numbers & extract the line & the line after each time. Might take some time to run though. |
|
#3
|
||||
|
||||
|
How about:
sed -n '/^11/{;p;n;p;q;}' This assumes that want only the first couplet that starts with 11. To get them all, omit "q;". |
|
#4
|
|||
|
|||
|
Thanks guys....
I like the sed option...but I think I found the same in awk..... awk -F"," ' /^11/ { print ; getline; print } ' my_file Cheers for your help.
__________________
Pete |
|
#5
|
||||
|
||||
|
Just to mix things up a little:
If you have GNU grep, you could do this: grep -A1 "^11" your_file |
||||
| Google The UNIX and Linux Forums |