Hi All,
I'm trying to add a carriage return to the end of my lines in a text file using substitution, but I havent found a way as yet.
Can anyone help?
something along the lines of:
:%s/<^A/^M/g obviously, this doesnt work.
Many thanks.
Hi All,
I'm trying to add a carriage return to the end of my lines in a text file using substitution, but I havent found a way as yet.
Can anyone help?
something along the lines of:
:%s/<^A/^M/g obviously, this doesnt work.
Many thanks.
I doubt that the pattern you are matching.Did you try,
:%s/$/^M/g
Where,^M - Ctrl-v+Ctrl-M
Thanks
Nagarajan G
Where,^M - Ctrl-v+Ctrl-M
I dont fully understand what your suggesting here, can you expand on what key strokes need to be input?
thanks, Ollie
I meant the keystrokes for getting ^M is ( you have to Hold Ctrl key and press v and then M )
Thanks
Nagarajan G
thanks, unfortunatley that doesnt work. Although it sends a carriage return, it doesnt translate when opened in a text file and still shows each line continuously.
I know if I can get a true ^M at the end of each line it will work..
any ideas?
If you open a file in vi and it is a continuous line, it means there are no carriage returns in your file (or at least any that vi understands), so s/$/^M/ will only put a ^M at the very end of the one big line. vi has no idea when your lines are supposed to end, how do you expect vi to recognize that?
I have no idea how you are trying to view this file, I'm guessing you are trying to view it in a windows app because you are trying to append ^M, and that is how vi "interprets" the DOS carriage return when vi opens a text file written in windows, but it doesn't mean that your windows app is going to interpret ^M as a carriage return, it is just going to see it as two characters: ^ and M.
Following on from this and still using substitution, is it possible to search and replace a field (column) rather than just a character/s?
I need a way of replacing a TAB between 2 fields with a single space.
i.e.
SURNAME FORENAME
to:
SURNAME FORENAME
Any ideas?
Are you trying to rewrite in shell the command ux2dos?
Hi
No, I'm not rewriting anything. Its simply a large text file where the first 2 columns are separated by a TAB and I want to substitute that for a single space.
My remark was more specifically for ^M at end of line...
Let me think a bit for the 2 columns...
OK,
substitution of <Tab> by <SpaceBar> works fine in vi using %s/press tab/one space/
:%s/ / /
thanks for this.
Problem is, I need a global substitution /g but ONLY for the first 2 columns. So I need to identify these in the pattern
Any ideas?