![]() |
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 |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|