Computing.Net > Forums > Unix > store a line from file in variable

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

store a line from file in variable

Reply to Message Icon

Name: Raxit
Date: February 28, 2003 at 11:20:08 Pacific
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



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: February 28, 2003 at 12:28:27 Pacific
Reply:

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



0

Response Number 2
Name: neel
Date: March 3, 2003 at 09:14:44 Pacific
Reply:

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 !]


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: store a line from file in variable

Process line from file -Cshell scr www.computing.net/answers/unix/process-line-from-file-cshell-scr/5072.html

read from file in shell script www.computing.net/answers/unix/read-from-file-in-shell-script/3803.html

removing specific line from file www.computing.net/answers/unix/removing-specific-line-from-file/5042.html