LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [c shell] printing out each line in a file (https://www.linuxquestions.org/questions/programming-9/%5Bc-shell%5D-printing-out-each-line-in-a-file-241422/)

saiz66 10-11-2004 02:43 PM

[c shell] printing out each line in a file
 
Hi. I want to know how to print out each line in a file. Thanks!

m00t00 10-11-2004 02:55 PM

cat file

where file is the file you want to look at.
Or use a pager.

less file
or
more file
or (if you have it)
most file

saiz66 10-11-2004 03:27 PM

sorry.. i wanted to print out each line of a file and save it into a variable so if i had a file with a word on each line:

monday is yesterday.
tuesday is today.
wednesday is tomorrow.

i want to put each of these lines into a variable...

e.g.
variable = monday is yesterday.
and so on putting each of the lines into that or a different variable.

how would i do that?

MrBrain 10-11-2004 11:57 PM

Code:

#!/bin/bash

#list the file into an variable
foo=$(cat your_file)
for var1 in $foo
do
        #do something with the result...
        #....
        #echo "current line from file:" $var1
done

Something like this perhaps.

saiz66 10-12-2004 08:15 AM

that is just perfect! thanks!


All times are GMT -5. The time now is 11:47 PM.