Mailinglist Archive: opensuse (1318 mails)

< Previous Next >
[opensuse] BASH - while read; howto read last line in file without blank line at end?
  • From: "David C. Rankin" <drankinatty@xxxxxxxxxxxxxxxxxx>
  • Date: Fri, 31 Oct 2008 22:51:43 -0500
  • Message-id: <490BD24F.109@xxxxxxxxxxxxxxxxxx>
Listmates,

I'm stumped on another simple BASH problem. How do I read the last line
of a
file with a while loop without requiring a blank line at the end of the file?
Simple example I'm stuck on:

{ while read alias url; do
echo -e "${alias}\t${url}"
done } < ~/linux/scripts/config/repos

The repos flat text file (shown with --- above and below to show no
blank line
at the end) is:

---
<snip: other repos>
database
http://download.opensuse.org/repositories/server:/database/openSUSE_10.3/
oss
http://download.opensuse.org/repositories/openSUSE:10.3/standard/
oss-src
http://download.opensuse.org/distribution/10.3/repo/src-oss/suse/
lastline temp-last_line_test
---

If there is no blank line at the end of the file, the while loop reads
the
"oss-src" line, but does not read the "lastline". If there is a blank line at
the end, it reads "lastline" just fine. What is the trick to be able to read
the last line of the repos file regardless of whether there is a blank at the
end or not?


--
David C. Rankin, J.D., P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
www.rankinlawfirm.com
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >