Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

$ ex -sc $'%s/\r$//e|x' file Perfectly works from the terminal from but when I try to run it with .sh script it simply ignores the lines after ex.

$ rm ~/Desktop/projectautomate/finalutf81.csv    
$ rm ~/Desktop/projectautomate/finalutf8.csv

$ cat ~/Desktop/projectautomate/headersutf8.csv ~/Desktop/projectautomate/upload.csv >> ~/Desktop/projectautomate/finalutf8.csv


$ iconv -f utf-16 -t utf-8 ~/Desktop/projectautomate/finalutf8.csv -o ~/Desktop/projectautomate/finalutf81.csv -c
$ ex -sc $'%s/\r$//e|x' ~/Desktop/projectautomate/finalutf81.csv

Every thing works but not the last line of command. I am basically trying to remove the CRLF (end line control characters) from the the file finalutf8.csv . Some detailed explanations would be appreciated. If not clear as English is my second language, I would try to explain it.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

What are these $ for?

#!/bin/sh
ex -sc '%s/\r//e|x' toto.txt

seems to work the way you want.

share|improve this answer
    
Thanks it works. some one in some blogs suggested to add $ before the codes. I am not sure if people use it here or not. Did't knew about #!/bin/sh. what is is actually for? Seems like #commented out but again it works. –  tough Jul 26 '12 at 9:57
1  
#!/bin/sh is used to tell your shell how it is supposed to interpret your script see here. You should put it on the 1st line of your shell script. –  romainl Jul 26 '12 at 13:05
    
Thanks, that was important to know for many other uses as well. –  tough Jul 26 '12 at 13:23

$'' is a bash thing only; the shell script is probably being executed with sh or dash. Put

#!/bin/bash

in the first line.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.