Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

sed command on several file in folder


How to execute below command on several files in a folder :
sed 's/$/\r/'  server_*.txt > server_*.txt

Thank you

Avatar of simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What are you trying to do?
Are you sure you are not inverting?

cat -v
Do you have ^M and that is what you want removed?

Dos2unix will fix left behind \r when transferring files

If you are using FTP to transferfiles, to avoid this issue an ascii cms before transferring text files.,

sed -pi.bak to create a backup file on which it acted.

Your attempt creates ambiguity
Avatar of bibi92


I have to change LF (\n) with  CRLF (\r\n)  
Thank you

Your attempt is to add a \r at the end of the line. \n\r is the end result of your script

Are you certain you currently do not have \r\n?

sed -pi.bak -e 's/\n/\r\n/g' list_of_files

How are you seeing that it is not present?
Hi Arnold, my sed command changes \n to \r\n as we hoped.

Also, 's/\n/\r\n/' doesn't do anything, since the substitution command never sees the "\n" (it only processes the text before the \n).
Avatar of bibi92


Are you certain you currently do not have \r\n? no because files txt are generated on linux servers and transferred on windows server for import them.
So I will test Simon script tomorrow.
Thank you  
When you transfer files from linux to windows, what are you uaing?
If FTP, make sure to use ASCII mode

How does this ahow.up?