The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
retrive value from a file satish@123 Shell Programming and Scripting 7 05-17-2008 05:57 AM
to retrive data that appear only once in a file. anibu Shell Programming and Scripting 1 10-26-2007 07:54 AM
Retrive deleted file's info asmita UNIX for Advanced & Expert Users 4 03-26-2007 10:36 PM
help to retrive data from log file d_swapneel14 Shell Programming and Scripting 5 07-06-2006 01:57 AM
need help appending lines/combining lines within a file... mr_manny Shell Programming and Scripting 2 01-06-2006 02:45 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-03-2008
Registered User
 

Join Date: Sep 2005
Posts: 25
retrive lines from a file using AWK command

Dear friends,
please tell me how to get some required lines from a file and write to another file using AWK command.
i.e.,
if a file contains,

abcdefghigk
12345
lmnopqrstuv

678910
wxyz


please tell me how to get lines(line count is always 2 and it's contineous) mentioned in blue colour from above file and write the same to another file.

thanks in advance,
swamymns
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-04-2008
Registered User
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 524
Are they always the second and third lines of the input file? If so, something like:

Code:
awk 'NR==2 || NR ==3' inputfile > outputfile
Alternatively, if it's always the line matching 12345 and the line after it:

Code:
awk '/12345/ { print ; getline; print }' inputfile > outputfile
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:14 PM.


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

Content Relevant URLs by vBSEO 3.2.0