Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

$ 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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .