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

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.

print a file line-by-line

Reply to Message Icon

Name: Br1an
Date: October 25, 2002 at 23:12:33 Pacific
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




Sponsored Link
Ads by Google

Response Number 1
Name: Br1an
Date: October 25, 2002 at 23:13:37 Pacific
Reply:

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


0

Response Number 2
Name: Sean Miller
Date: October 26, 2002 at 01:33:59 Pacific
Reply:

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


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

Reading a file line by line www.computing.net/answers/unix/reading-a-file-line-by-line/5633.html

read a file line by line in unix www.computing.net/answers/unix/read-a-file-line-by-line-in-unix/7334.html

reading from a file in unix www.computing.net/answers/unix/reading-from-a-file-in-unix/7355.html