Computing.Net > Forums > Unix > Process line from file -Cshell scr

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.

Process line from file -Cshell scr

Reply to Message Icon

Name: Shailesh
Date: May 22, 2003 at 05:21:21 Pacific
OS: UNIX
CPU/Ram: SPARC
Comment:

Hi,

I want to read a file in a C shell script and process all the words of each line as a command set.

something like this

read line from file
get the first word from line and assign it to a variable
get the second word and assign to another variable
process based on these variables.
read the second line from file
...
....


Thanks
Shailesh




Sponsored Link
Ads by Google

Response Number 1
Name: twisgabak
Date: May 26, 2003 at 19:39:24 Pacific
Reply:

Hi!

try this:

## start
FILE_NAME=test.txt

#code to change separator(see note)

for value in `cat $FILE_NAME`
do
echo $value
done

## end

For the separator, I can't remember the reserved shell variable, but usually it is set to space, tab and \n. But you can modify it so the for loops one line at the time(if you let only \n in this variable). Check into the shell documentation (Unix in a nutshell from O'Reilly is a good book for that)...

Hope this help!

Twisgabak


0
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: Process line from file -Cshell scr

extract a specific line from file www.computing.net/answers/unix/extract-a-specific-line-from-file/5381.html

store a line from file in variable www.computing.net/answers/unix/store-a-line-from-file-in-variable/4659.html

to remove duplicate lines from file www.computing.net/answers/unix/to-remove-duplicate-lines-from-file/7011.html