X-Spam-Check-By: sourceware.org Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" 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 References: A From: "Williams, Gerald S \(Jerry\)" To: Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Content-Transfer-Encoding: 8bit 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/