Dr. Werner Fink wrote:
On Thu, Sep 04, 2008 at 01:10:16AM -0500, David C. Rankin wrote:
Listmates,
I stumbled on a problem trying to read a file (email mailbox) line-by-line in bash. Using the built-in read, it strips the leading whitespace from each line making the subsequent write impossible. I was using a while loop as follows:
{ while read XTAG VALUE LINE; do if [[ ${XTAG} == "X-Mozilla-Status:" ]]; then case ${VALUE} in <snip>
All of the lines in the mailbox with leading whitespace were written without the leading whitespace like:
Just use the IFS variable.
while IFS=$'\n' read line ; do if [[ $line =~ ^X-Mozilla-Status: ]] ; then value=${line#*:} value=${value%%[[:blank:]]*} case $value in 1019 ) line=${line/1019/1011} ;; 1009 ) line=${line/1009/1001} ;; 001b ) line=${line/001b/0013} ;; 0019 ) line=${line/0019/0011} ;; 000b ) line=${line/000b/0003} ;; 0009 ) line=${line/0009/0001} ;; esac fi echo "$line" >> ${NEWFILE} done < ~/.thunderbird/2k12pnl0.default/Mail/pop.suddenlinkmail.com/openSuSE.sav
<snip>
Werner
Thank you Dr. Fink, Patrick, Brian and Per, This is exactly what I was trying to do. I had been over the Parameter Expansion section of man bash several times, but could not figure out how to put the pieces of the puzzle together. This hit the nail on the head. The sed example was something I had looked at but decided against due to the overhead of repeated sed calls ( 3,869,388 times adds up ). The IFS environment discussion was also good learning as I routinely used OLDIFS to hold and reset the IFS variable, many times when it wasn't needed. Thanks again! -- 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@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org