![]() |
|
|
|
|
|||||||
| 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 |
| Pattern matching in file and then display 10 lines above every time | namishtiwari | Shell Programming and Scripting | 16 | 4 Weeks Ago 07:50 PM |
| Display lines of the file on a log | sbryant | Shell Programming and Scripting | 2 | 02-26-2008 11:16 AM |
| display all lines | shary | Shell Programming and Scripting | 3 | 02-17-2007 01:09 PM |
| display no of empty lines | atticus | Shell Programming and Scripting | 5 | 03-22-2006 12:35 PM |
| display a portion of lines from file | champion | UNIX for Dummies Questions & Answers | 6 | 09-20-2005 08:11 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
display few lines of the file
Hi,
If I want to have a look at few lines of the file, how do I, what command to use. Eg: If I have a file having length 2000 lines and I want to have a look at the content between 1400 and 1600, How do I look at it ? Also, If I want to have a look at function alone in a file, how do I go about it ? Eg: If I have a file with 7 functions and Main part. And one function is : sub sample { ---- ---- ---- return 1; } And If I want to get only the contents of this function from file, How do I get it ? Thanks, Sharath
__________________
K.S.SHARATH CHANDRA |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
I tend to agree with Driver...
If you can read a 2000 line script with Functions in it... you should know how to use "vi" and file manipulation to view a file. Please, defend your question, or I might have to close this post. Here is a great link for Vi related questions. http://www.thomer.com/vi/vi.html
__________________
My brain is your brain |
|
#3
|
|||
|
|||
|
Hi Driver,
This is not a HOMEWORK question. Head has one option -n to display first n number of lines in a file. Which won't serve my purpose. Tail does samething from opposite direction and hence no use either. I wanted a combination to get a range of lines. More specifically, I wanted to extract a function block from the file. ( I have around 20 similar programs written in perl and all have few common functions. I need to change these functions now. In order to verify I didn't want to open again using "vi". Hence the need was to a have look at the function block in all files and verify the changes.) I didn't get what Kelam_Magnus is saying. I have gone through the link given on Vi few times long back and thanks for reminding me on the same. I will go through the page again as it gives lot of pleasure in reading the same. Thanks, Sharath
__________________
K.S.SHARATH CHANDRA |
|
#4
|
||||
|
||||
|
Re: display few lines of the file
You can use awk start/end pairs too....
Quote:
awk 'NR==1400,NR=1600' file1 Quote:
awk '/sub sample/,/}/' file1 |
|
#5
|
||||
|
||||
|
Driver,
My point was that in awk you can use start/end pairs. i.e. two patterns or conditions sepated by a comma. All you have to do is determine what the conditions are. My post works with the sample supplied. But with the sample you have supplied, the end condition might be "/^}$/" , i.e. a line that is one "}" on its own with no whitespace. So you would have... awk '/sub foo/,/^}$/' file ...which could be the simplest solution, but perhaps more work is needed. It would be more efficient to use "exit" to stop reading the file when the end condition is reached. The idea of counting matched braces can be coded more simply as .... awk '/sub foo/,0 {print;b+=gsub("\{","{");b-=gsub("\}","}");if(b==0)exit}' file |
||||
| Google The UNIX and Linux Forums |