The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-28-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
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  
Old 08-29-2002
Registered User
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
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  
Old 08-29-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
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  
Old 08-29-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
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  
Old 08-29-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0