Computing.Net > Forums > Unix > print a file line-by-line

print a file line-by-line

Reply to Message Icon

Original Message
Name: Br1an
Date: October 25, 2002 at 23:12:33 Pacific
Subject: print a file line-by-line
OS: Unix
CPU/Ram: 256
Comment:

Hi,
if i got a file "foo.txt":
aaa
bbb
ddd
aaa

and i want to print the file out line-by-line,then how to do that ?
thanks a lot



Report Offensive Message For Removal


Response Number 1
Name: Br1an
Date: October 25, 2002 at 23:13:37 Pacific
Subject: print a file line-by-line
Reply: (edit)

...i mean in a script, if i want to read that file "foo.txt" and print out its contents line by line.
Thanks


Report Offensive Follow Up For Removal

Response Number 2
Name: Sean Miller
Date: October 26, 2002 at 01:33:59 Pacific
Subject: print a file line-by-line
Reply: (edit)

I am assuming by "print" you mean "echo" ?? However, the rule would be the same for print -- see commented out line below.

The IFS sets the "input file seperator" which, by default, is space. What we're doing here is setting to be carriage return (ie. end of line). ^M means a physical ctrl-M (carriage return) -- in vi to do it use ctrl-V ctrl-M

#!/bin/ksh

IFS="^M"

for i in `cat foo.txt`
do
echo $i
# echo $i | lp
done


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: print a file line-by-line

Comments:

 


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