Date: Mon, 15 Oct 2001 01:10:59 -0400 From: Jim Conner <jconner@enterit.com> To: <doug@safeport.com> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: sh script question Message-ID: <5.1.0.14.0.20011015010540.02b65280@mail.enterit.com> In-Reply-To: <Pine.BSF.4.21.0110142012320.23659-100000@pemaquid.safeport .com>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an excellent question. One that I would resolve by the following:
At 21:09 10.14.2001 -0400, doug@safeport.com wrote:
>I want to read a file line-wise. The following:
>_______________
>#!/bin/sh
>USER="doug"
>FILE="newuser.form"
Good so far but I would go ahead and assign $File:
FILE=${FILE:-1}
>if [ ! -e $FILE ]; then
> echo "File: $FILE not found"
> exit 1
>fi
Still good...
>for Line in `cat $FILE`; do
> echo $Line
>done
I prefer to do things like this for a line by line read without affecting
the IFS env variable.
while read -r line
do
echo $line
done < $FILE
That will work fine. Now, if you want to go the route you were above by
affecting the IFS variable then you can set IFS like this:
IFS="\n"
for line in $(cat $FILE)
do
echo $FILE
done
Let me know what you end up choosing. BTW, I use ksh as my shell of choice
for scripting. If sh doesn't understand the above substitution for IFS try
ksh.
- Jim
>---------------
>
>gives the file a field per read. The field delimiter being
>blank/whitespace. The
>obvious answer would seem to be "IFS=<newline>" but I can not figure out the
>syntax or even if that is possible.
>
>Thanks for any pointers
>
>_____
>Douglas Denault
>doug@safeport.com
>Voice: 301-469-8766
> Fax: 301-469-0601
>
>
>To Unsubscribe: send mail to majordomo@FreeBSD.org
>with "unsubscribe freebsd-questions" in the body of the message
- Jim
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
http://www.perlmonks.org/index.pl?node_id=67861&lastnode_id=67861
-----BEGIN PERL GEEK CODE BLOCK----- ------BEGIN GEEK CODE BLOCK------
Version: 0.01 Version: 3.12
P++>*@$c?P6?R+++>++++@$M GIT/CM/J d++(--) s++:++ a-
>++++$O!MA->++++E!> PU-->+++BD C++++(+) UB++++$L++++$S++++$
$C-@D!>++++(-)$S++++@$X?WP+>++++MO!>+++ P++(+)>+++++ L+++(++++)>+++++$ !E*
+PP+++>++++n-CO?PO!o >++++G W++(+++) N+ o !K w--- PS---(-)@ PE
>*(!)$A-->++++@$Ee---(-)Ev++uL++>*@$uB+ Y+>+++ PGP t+(+++)>+++@ 5- X++ R@
>*@$uS+>*@$uH+uo+w-@$m! tv+ b? DI-(+++) D+++(++) G(++++)
------END PERL GEEK CODE BLOCK------ ------END GEEK CODE BLOCK------
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5.1.0.14.0.20011015010540.02b65280>
