delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/04/09/11:00:59

X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
Subject: RE: Using dos2unix and attaching it to a while loop
Date: Mon, 9 Apr 2007 11:00:22 -0400
Message-ID: <4C89134832705D4D85A6CD2EBF38AE0FE3BDC8@PAUMAILU03.ags.agere.com>
In-Reply-To: A<heqj1318dq537pgisa6q4en46p227nrcll@4ax.com>
References: A<heqj1318dq537pgisa6q4en46p227nrcll AT 4ax DOT com>
From: "Williams, Gerald S \(Jerry\)" <Jerry DOT Williams AT lsi DOT com>
To: <cygwin AT cygwin DOT com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id l39F0mAk032412

robert_neville310 AT yahoo DOT com wrote:
> I am dealing with DOS text files and need to output DOS text files.
[...]
> I found dos2unix, but I do not know how to properly implement it. The
> following Bash code is a work-in- progress. Please let me know if a
more
> efficient approach exists. 
> 
> while read line
> 	do
> 		i=0
> 		echo "LINE -> $line"
> 		echo "i -> $i"
> 		MP3[i++]=$(awk '/^.*\.mp3/ { print $1}')
> 		CRC[i++]=$(awk '/^.*\.mp3/ { print $3}')
> 		echo "MP3[i] -> $MP3[i]"
> 		echo "CRC[i] -> $CRC[i]"
> 	done < <(dos2unix "$FILE")
> 
>  #do some stuff  then
> unix2dos "$FILE"
> 
> The cygwin console returns the following error. My syntax is not
correct.
> 
> FileRenamer3.sh: line 132: syntax error near unexpected token `<'
> FileRenamer3.sh: line 132: `          done < <
> (dos2unix "$FILE")'

There are many problems with that code snippet. I'll start by answering
your question:

-----

Yes, that format is incorrect. I think perhaps you are confusing the
$(...) operator, although that's not really what you want either.

"dos2unix FILE" converts the file in place, so to use that form you
would simply do this:

 dos2unix "$FILE"
 while read line
 do
     ...
 done < "$FILE"
 unix2dos "$FILE"

If you want convert the contents of "$FILE" without changing the file
in place, you could use dos2unix as a filter as follows:

 dos2unix < "$FILE" | while read line
 do
     ...
 done

-----

I also noticed that i is reset to zero on each pass, then incremented
in a presumably incorrect manner. This code sets MP3[0] and CRC[1] on
each pass, then tries to print ${MP3[2]} and ${CRC[2]}. I'm reasonably
certain that you also don't want to run awk quite the way you're doing
it--perhaps you meant to do something like $(echo "$line" | awk ...)?
Finally, "$MP3[i]" doesn't access array elements, nor does it expand
the value of i--I think you meant "${MP3[$i]}". But as you said it is
a work in progress...

-----

gsw

Disclaimer: I rarely use BASH myself, although I do quite a bit with
ZSH (because I can), KSH (because I have to), and SH (because we all
ought to). :-)

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019