title: convert the CR/LF line terminators in that file to Unix-style LF line terminators?
body: <p>Please help. I need to turn this in before 4pm for this Unix class. I have been working on it since 7pm last night. Haven't slept. There are three parts to this assignment. I only need help with the last part. If I can't complete this I fail the class.</p>
  
  <p>Stage 3</p>
  
  <p>In that same directory, write a script asciiFix.sh that takes an arbitrary number of file paths from the command line and carries out the same analysis on each one. If a file is not Windows ASCII, your script should do nothing to it. For each file that is Windows ASCII, your script should print the message</p>
  
  <p>converting <em>fileName</em></p>
  
  <p>and should then convert the CR/LF line terminators in that file to Unix-style LF line terminators.</p>
  
  <p>For example:</p>
  
  <pre><code>cp ~cs252/Assignments/ftpAsst/d3.dat wintest.txt
  ./asciiFix.sh /usr/share/dict/words wintest.txt fileType.sh  
  converting wintest.txt
  and, after the script has finished, you should be able to determine that wintest.txt is now a     Unix ASCII file.
  </code></pre>
  
  <p>When you believe that you have your script working, run</p>
  
  <p>~cs252/bin/scriptAsst.pl
  If all three scripts are working correctly, you will receive your access code.</p>
  
  <p>My Attemps: </p>
  
  <pre class="lang-css prettyprint-override"><code>#!/bin/sh
  for file in "$@"  do
       if file "$file" | grep "ASCII text, with CRLF"; then
       echo "converting $file"
       sed -e s/[\\r\\n]//g "$file"
   fi    
  done
  </code></pre>
  
  <p>
  result:</p>
  
  <pre><code>    ./asciiFix.sh: 3: ./asciiFix.sh: Syntax error: "if" unexpected (expecting "do")
      aardvark.cpp /home/cs252/Assignments/scriptAsst/winscrubbed.dat differ: byte 50, line 1
  
      Failed: incorrect file conversion when running ./asciiFix.sh 'aardvark.cpp' 'bongo.dat'    '     cat.dog.bak
  </code></pre>
  
  <p>Ii have tried taking out if and then. i have tried sed -i 's/^M//g' "$file",also using dos2unix, as well as some other stuff I dont remember. but it always says incorrect conversion with those files.</p>
  
  <p>After adding the ; and switching to dos2unix:</p>
  
  <pre><code>#!/bin/sh
  for file in "$@";
  do
       if file "$file" | grep "ASCII text, with CRLF"; then
       echo "converting $file"
       dos2unix "$file"
   fi    
  done
  </code></pre>
  
  <p>the Error that I now get:</p>
  
  <pre><code>dos2unix: converting file aardvark.cpp to Unix format ...
  
  Failed when running: ./asciiFix.sh 'aardvark.cpp' 'bongo.dat' 'cat.dog.bak'
  </code></pre>