| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
store a line from file in variable
|
Original Message
|
Name: Raxit
Date: February 28, 2003 at 11:20:08 Pacific
Subject: store a line from file in variable OS: hpux CPU/Ram: 200
|
Comment: hi, i need to pick up a line from a file and store it in a variable.i dont know the number of lines that the file contains...so i cannot specify it by a linenumber. i need to continue this till the last line of the file. so i think it has to be proabably some type of a loop. please help thanks
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: nails
Date: February 28, 2003 at 12:28:27 Pacific
|
Reply: (edit)Raxit: You're right, it's a loop: while read line do echo $line done data.file # need a less than sign between "done" # and "data.file" The above reads each line of data.file. You've neglected to tell us how to identify the line you want. Regards, nails
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: neel
Date: March 3, 2003 at 09:14:44 Pacific
|
Reply: (edit)Raxit, You can try with this one also ... #!/bin/sh IFS=' ' for i in `cat data_file` do ### If you are matching the whole line. if [$i = "Something you are searching"] then echo "U found me" fi ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Or if you are searching for a particular line number wherer you will find that line or hae a match .. you can use this.. cat -n file_name | grep "whatever u r searching" | awk -F" " '{print $1}' it will give you the line number in the file .. [ it wont consider the blank lines !]
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Unix Forum Home