2007/2/22, Ag. Hatzimanikas <[EMAIL PROTECTED]>:

What I want to see from Warren and in a way that also would be beneficial
for
the list,is to translate the human logic to actions and code.


What I got:

pseudo code:
- recursively find files from current directory
   for each file found:
      - test whether it ends with dos line terminators, eg. CRLF
          if so:
              - change the line terminators into linux line terminators
              - overwrite the file
              - echo the filename so it is visible that something happened
     - test whether it ends with an .sql extension
          if so:
             - test whether the last character in the file is not a $
(linefeed)
                   if so:
                        - insert  the $
                        - overwrite the file
                        - echo the filename so it is visible that something
happened



Then we can translate the above paragraph to a snippet of code and do the
job.


I took a shot at it, but I am missing the linefeed check and insert linefeed
stuff.

#!/bin/bash
for filename in $(find . -type f);do
      if [[ -n $(file $filename |grep CRLF) ]]
      then
          sed 's/^M$//' $filename > $filename.unix
          echo File converted from dos to unix: $filename
      fi
      if [[ -n $(echo $filename | grep .sql) ]]
      then
          if [[ -n (cat -E $filename | findthelastcharacterisnot$) ]]
          then
              insert a line feed
              overwrite the file
              echo File had a LF inserted: $filename
          fi
          # echo File ends with .sql: $filename
      fi
done
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to