![]() |
|
|
|
|
|||||||
| 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 |
| cutting a section of a big file | yoavbe | Shell Programming and Scripting | 6 | 07-21-2008 11:00 AM |
| Using Sed to duplicate a section of a file.... | nick26 | Shell Programming and Scripting | 2 | 05-01-2008 08:18 AM |
| sed & awk--get section of file based 2 params | Andy Cook | Shell Programming and Scripting | 12 | 12-01-2006 12:28 PM |
| getting error 0403-016 Cannot find or open the file while reading a long line | karthee | Shell Programming and Scripting | 2 | 06-04-2005 09:00 PM |
| New Section | kapilv | Post Here to Contact Site Administrators and Moderators | 3 | 10-31-2001 06:57 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
help find a section line of a file
hi,
I have a 20 line file. I need a command which will brinf back a specific line based upon the line number I enter. e.g. the file looks like this and is called file1 jim is a man john is a woman james is a man wendy is a woman lesley is a woman i want a command that will output any one of this lines based upon the number i pass it as parameter. eg. $ ./script file1 2 (script being the command) will show $ john is a woman any help will be much appreciated thanks in advance Suresh
__________________
All I wanna o is live like the kings do. All I wanna be is smarter than my enemy. All I wanna have is everythng I haven't got. All I wanna take is everything they make. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
sed -n 2p file1
should do it. |
|
#3
|
||||
|
||||
|
Alternatively,
awk NR==2 file1 |
|
#4
|
||||
|
||||
|
Quote:
Code:
#!/bin/sh sed -n $2p $1 awk NR==$2 $1 You could also implement error checking by ensuring that the file passed exists (look at the "test" or "[" builtins/commands).... Cheers ZB |
|
#5
|
|||
|
|||
|
Sorry this is late..
Many Thanks, much appreciated.
__________________
All I wanna o is live like the kings do. All I wanna be is smarter than my enemy. All I wanna have is everythng I haven't got. All I wanna take is everything they make. |
|||
| Google The UNIX and Linux Forums |