The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
print all even lines of a txt file ajp7701 Shell Programming and Scripting 1 04-17-2008 11:17 PM
Print out a row of data Streetrcr UNIX for Dummies Questions & Answers 4 03-17-2008 06:57 AM
print out result from data file thms_sum Shell Programming and Scripting 8 01-30-2008 11:32 AM
Pulling data and following lines from file MizzGail Shell Programming and Scripting 2 01-31-2006 03:13 PM
Print only certain lines from a text file CamTu Shell Programming and Scripting 1 06-01-2005 11:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 3.00 average. Display Modes
  #1 (permalink)  
Old 04-28-2006
kamesh83 kamesh83 is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 8
How to print data between 2 lines in a file

i want to print the data between two line numbers in file to another file.
which command should i use

i tried sed command . i am storing the line numbers in two variables say L1,L2. but $L1 and $L2 are not working in sed command.

is there any other command to do this
reply soon
  #2 (permalink)  
Old 04-28-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
What sed command did you try ?
  #3 (permalink)  
Old 04-29-2006
kamesh83 kamesh83 is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 8
Smile hey thanks for ur reply yaar

hey i got the solution to the above problem.

i used the sed command sed -n " $L1,$L2 w outfile" inputfile where L1 and L2 are variables which contains line numbers.

previously i used the same command but with ' qoutes instead of " quotes.


Any have thanks for showing interest to solve my problem
  #4 (permalink)  
Old 10-20-2008
Satyak Satyak is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 85
i am using sed -n "$lineno1 $lineno2 w OUT.FILE" $infile , but i got the error

sed: -e expression #1, char 3: Unknown command: `1'

please help
  #5 (permalink)  
Old 11-04-2008
igorc igorc is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 7
Try with awk:

cat -n test.log | awk '{if((NR>122)&&(NR<128)) print}'

for a test to see if it is working (this should print the lines from number 123 to 127. Then you can remove 'cat' and the command should be:

awk '{if((NR>122)&&(NR<128)) print}' test.log

Hope this will work for you (works for me )

If you want to use line numbers dynamically as variables, then use nawk instead awk:

nawk -v l1=$L1 -v l2=$L2 '{if((NR>l1)&&(NR<l2)) print}' test.log

Last edited by igorc; 11-04-2008 at 08:20 PM..
  #6 (permalink)  
Old 12-18-2008
saltie saltie is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 1
Very helpful thank you!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0