You are not logged in.

#1 2006-07-20 18:19:07

curana
Member
From: Switzerland
Registered: 2006-04-14
Posts: 97
Website

Remove "^M" out of files created with Windows

Hi,

Im trying to set up "OpenBox" but I dont want to type all the configfiles by hand. But as there is no software linked in OpenBox yet, I only have FireFox installed big_smile

Now I was so clever (!) to copy and paste the configs in Windows and sent by mail to my Linux-system. So far, so good.

When I open the files (sh-scripts etc) I have these ugly Windows-$%&!%%! in these files. The files/scripts are quite long so I dont want to remove by hand.

Can u give me a hint how to remove them using vi automatically? If I remember well there was a command for tha... ("Hallo brain, nobody there?")

Would be great if somebody could help.
Thanks for your efforts,

The Pope

Offline

#2 2006-07-20 18:24:43

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: Remove "^M" out of files created with Windows

Use hd2u (pacman -S hd2u).

Offline

#3 2006-07-20 18:25:36

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Re: Remove "^M" out of files created with Windows

cat windowsconfig | sed 's/^M$//' > linuxconfig

And to type the ^M, do ctrl-v then ctrl-m

Offline

#4 2006-07-20 18:28:07

curana
Member
From: Switzerland
Registered: 2006-04-14
Posts: 97
Website

Re: Remove "^M" out of files created with Windows

@Snowman: Thanks a lot! Big help!!!
@codema: Thanks for the hint, but I am really happy to get rid of these..."symbols"

Offline

#5 2006-07-20 22:36:48

alexpnx
Member
From: Nicosia, Cyprus
Registered: 2006-06-10
Posts: 47

Re: Remove "^M" out of files created with Windows

another alternative is dos2unix

Offline

#6 2006-07-21 05:25:44

curana
Member
From: Switzerland
Registered: 2006-04-14
Posts: 97
Website

Re: Remove "^M" out of files created with Windows

@alexpnx: Its strange, I used pacman -S hd2u but used the the command dos2unix -a (...). Means hd2u=dos2unix or dos2unix is part of the base-system (no other packages installed)?

Offline

#7 2006-07-21 06:37:30

phildg
Member
Registered: 2006-03-10
Posts: 146

Re: Remove "^M" out of files created with Windows

If you look at the description for hd2u:

dos2unix is filter used to convert plain texts from DOS (CR/LF) format to UNIX format (CR) and vice versa.

And if you look at the file list you'll see that dos2unix belongs to the hd2u package

Offline

#8 2006-07-21 15:46:01

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Re: Remove "^M" out of files created with Windows

curana wrote:

@codema: Thanks for the hint, but I am really happy to get rid of these..."symbols"

... what does that mean?  My sed _does_ get rid of them.  I told you how to type the ^M in the sed script, you need to be using the escape character, not just typing ^M in the console.

Offline

#9 2006-07-21 18:30:32

curana
Member
From: Switzerland
Registered: 2006-04-14
Posts: 97
Website

Re: Remove "^M" out of files created with Windows

@codemac: I dont get it. But no need, I figured it out. Thanks anyway...

Offline

#10 2006-07-22 04:38:35

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Re: Remove "^M" out of files created with Windows

ok, I really want to get this accross, because you really don't need a binary for every job.  That's part of the philosophy of Unix, using general purpose binaries together to do specific tasks.

In this case 'cat' and 'sed'

The first part of the command is 'cat windowsConfig |', putting the file with the annoying ^M onto stdin for the next app on the command line.

The next part is 'sed s/^M$//'.  This is the part you aren't understanding.  Type "sed s/" then ctrl-v and then ctrl-m. You will then see "sed s/^M" on the console.  Type the rest with "$//".  The dollar sign means "end-of-line" in Regular Expressions.  This command literally means replace ^M$ with nothing.

Thus the resulting command :

cat windowsConfig | sed "s/^M$//" > linuxConfig

If you don't get it yet, google "regular expressions", and be amazed how much of your life has been wasted not knowing them.

Offline

#11 2006-07-22 05:13:49

curana
Member
From: Switzerland
Registered: 2006-04-14
Posts: 97
Website

Re: Remove "^M" out of files created with Windows

Now I got it... Im sorry for being a little slow in understanding.

Originally, as you can see in my first post, I was looking for sth like that and somehow "know" this feature, Im just not yet familiar with the expressions and syntax. For the moment I just needed a fast and simple solution and the binary was right in time smile

Anyway, thanks a lot, I will make myself familiar with these expressions. Seems really very useful.

Thanks for ur explanation!!!

Offline

#12 2006-07-22 08:26:46

vacant
Member
From: downstairs
Registered: 2004-11-05
Posts: 816

Re: Remove "^M" out of files created with Windows

How about this?

tr -d 'r'  <  INPUTFILE  > OUTPUTFILE

(I'm in the process of installing a Smoothwall box at Cybercafé)

Offline

Board footer

Powered by FluxBB