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

Process line from file -Cshell scr

Reply to Message Icon

Original Message
Name: Shailesh
Date: May 22, 2003 at 05:21:21 Pacific
Subject: Process line from file -Cshell scr
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



Report Offensive Message For Removal


Response Number 1
Name: twisgabak
Date: May 26, 2003 at 19:39:24 Pacific
Subject: Process line from file -Cshell scr
Reply: (edit)

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Process line from file -Cshell scr

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software