Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Reading line by line
- X-seq: zsh-users 11384
- From: sac <sac_urs@xxxxxxxxxxx>
- To: meino.cramer@xxxxxx, zsh-users@xxxxxxxxxx
- Subject: Re: Reading line by line
- Date: Wed, 11 Apr 2007 10:49:17 -0700 (PDT)
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.co.in; h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=q5Klq4RHcpzbY2ue7ZZ9WJbWjsK89/BqhXoTb5bVDoxnh/0udbhnoxoHoJjc4n/z0kMPseaodt4XKmh5l6sgybA1sx5S5VIokeeiwpLxB+seJ1Cmie8JkJbPnQHJ0y7cgzUk3/bCCjGqHaz0C5uvRvA8t1gd0V3PSle6e8Tb2f0=;
- In-reply-to: <20070411033311.GA6837@solfire>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
Hi,
Actually there are many ways to read the file line by
line. Three of the popluar ones are:
1.
for i in `cat filename`
do
echo $i
done
* This method works only if the file has only single
word in every line. Else it fails
2. Like Micah J. Cowan pointed out,
while read i
do
echo $i
done < filename
3. The below example is taken from
http://open.itworld.com/5040/nls_unix_filedescriptor060608/page_1.html
$ read <&3 myline
The variable "$myline" will then contain the first
line from the file. Repeat the read command and we
will get the second line and so on. We might,
therefore, use a script like that shown below to read
and process each line in a file. Notice the comments
inserted into the spot where we would process each
line in some way in whatever way we want.
if [ $# != 1 ]; then
echo "Usage: $0 input-file"
exit 1
else
infile=$1
fi
# assign file descriptor 3 to input file
exec 3< $infile
until [ $done ]
do
read <&3 myline
if [ $? != 0 ]; then
done=1
continue
fi
# process file data line-by-line
# in here ...
echo $myline
done
echo "The End"
Regards,
sac.
--- meino.cramer@xxxxxx wrote:
> Hi,
>
> how can I read line by line from a file of text?
>
> I tried
>
> while theline in `cat results.txt`
> do
> echo ${theline}
> echo "----------------"
> done
>
> and got a new echo on every _blank_ seperated word
> and
> not a every new line seperated by a newline.
>
> Thank you very much for any help in advance!
> Keep zshing!
> mcc
>
>
>
> --
> Please don't send me any Word- or
> Powerpoint-Attachments
> unless it's absolutely neccessary. - Send simply
> Text.
> See
>
http://www.gnu.org/philosophy/no-word-attachments.html
> In a world without fences and walls nobody needs
> gates and windows.
>
____________________________________________________________________________________
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367
Messages sorted by:
Reverse Date,
Date,
Thread,
Author