This is just kind of weird. I was going to ask about this very thing when I came to the board, and the question is up on top.
I was wondering about using sed to do the trick. I am running Linux with GNU sed version 4.1.5. Anyway, I had a file which was peppered with ^M characters. I tried this:
But it did not seem to do the trick. What did I do wrong?
edit::
Ah - I just tried doing <CTRL-V> <CTRL-M> and it worked. So thanks sb008..
So my next question is about the <CTRL-V> <CTRL-M> sequence. Why is <CTRL-V> necessary? What is happening when it is used?
The newliine in a DOS/Windows environment is CRLF.
The newline in an Unix environment is only LF.
When you e.g. frp a TEXT file from a DOS/Windows system to an Unix system in ASCII mode the CRLF is automatically converted to a LF only.
When ftp'ing this same file in BIN mode the conversion doesn't take place.
This means that in this case a file will contains an unnecessary CR at the end of each line on the Unix system .
This CR is visually represented by the ^M.
Therefore this ^M is a SINGLE character, representing the CR, and not the 2 characters ^ and M.
The CTRL-V can be considered as calling the "composed character" function.
So pressig CTRL-V + CTRL-M composes the SINGLE character ^M.
This always works within "vi", however not always on the commad line.
If you are using e.g. a "ksh" with an "emacs" command line interface, pressing CTRL-V on the command line will result in displaying the version of your "ksh". Therefore CTRL-V+CTRL-M will not work on the command line when using ksh/emacs.
Thankyou all,
I am getting several files with extra characters. So, I cannot do it by going into vi. I will have to do it by command line. As long as I don't use ksh/emacs, I should be ok?? Am I right. I am only using sh(bourne).
Also, I am just not seeing ^M but also ^@. SO will ^V-^@ also will similarly ??
Thankyou all,
I am getting several files with extra characters. So, I cannot do it by going into vi. I will have to do it by command line. As long as I don't use ksh/emacs, I should be ok?? Am I right. I am only using sh(bourne).
Also, I am just not seeing ^M but also ^@. SO will ^V-^@ also will similarly ??
Thanks
You could still go ahead with the sed command i suggested above by changing the characters something like this
Last edited by ahmedwaseem2000; 02-12-2007 at 02:20 PM..
Why in the world is everyone playing around with sed and tr and who knows what else?! On Solaris and Linux, you can use dos2unix and unix2dos to remove and add the ^M characters. On HP-UX, dos2ux and ux2dos does the same thing.
Why in the world is everyone playing around with sed and tr and who knows what else?! On Solaris and Linux, you can use dos2unix and unix2dos to remove and add the ^M characters. On HP-UX, dos2ux and ux2dos does the same thing.
Maybe because he mentioned in his initial question he tried dos2unix and stated it didn't work
Hi there,
Im having a bit of difficulty with this one and I suspect its because of the character I want to match against maybe causing me a problem, but i wanted to remove everything up to (but not including) the first instance of '{' in a string
so for example the string that I want to... (2 Replies)
I have been given a shell script that I need to amend. To do the following
extract the filename from the flag file by removing the .flag extension.
# Local variables
# Find if the flag files exists
MASK=coda_mil2*.flag
# Are there any files?
bookmark="40"
fileFound=0
ls -1... (3 Replies)
Hi,
in a file, i have records as below:
123|62|absnb|267629
123|267|28728|uiuip
123|567|26761|2676
i want to remove the non printable characters after the end of each record.
I guess there are certain charcters but not visible.
i don't know what character that is exactly.
I used... (2 Replies)
Dear Friends,
I want to remove text between two patters.
Problem is, it has random special characters like \ / | * ` ~ ! $ etc.
These random special characters has no fixed length. But these special characters are appearing between a fixed pattern
e.g.
DM&^%#|#!\/?CT
Expected output... (14 Replies)
hi
I have a perl script conv.pl. when i execute this file and direct i to log file I see lots of ^M characters in the log file. There is no ^M in conv.pl file. Log file is generated only after conv.pl is executed.
Please help as how to get rid of these.
This conv.pl is going to get schduled... (5 Replies)
hi
I have a perl script conv.pl. when i execute this file and direct i to log file I see lots of ^M characters in the log file. There is no ^M in conv.pl file. Log file is generated only after conv.pl is executed.
Please help as how to get rid of these.
This conv.pl is going to get schduled... (0 Replies)
Hi all,
Any help on how to do the following? :eek:
I have an infile as follows:
_thisishowyouwritehelloworld
_thisisalsohowyouwritehelloworld2
I want to delete the characters from "_" to "how" and be left with:
youwritehelloworld
youwritehelloworld2
I am able to do delete from a... (2 Replies)
Hi,
I have a very huge file and it contains some unprintable characters like ^H and ^D.
If I try to remove using cat test1.ser| tr -d '\136 110'>newfile1 it is only removing ^and all spaces in the file.
How can I remove these characters (^D ^H) and keep my spaces as it is?
Thanks &... (1 Reply)
Hi
I have a file that has semicolons in it (;) is there a way to just remove these in the file. Example
name: Joe Smith; group: Group1;
name: Mary White; group: Group2; (2 Replies)