How to exchance characters in a file
I have this odd file filled with the remains of a psion-file that was corrupted. It seems fields are delimites with a $ sign. How can i quickly exchange those for a CR/LF combination ? /me needs desperately to learn shell scripting and or Perl... -- /Rikard ----------------------------------------------------------------------------- email : rikard.j@rikjoh.com web : http://www.rikjoh.com mob: : +46 (0)763 19 76 25 ------------------------ Public PGP fingerprint ---------------------------- < 15 28 DF 78 67 98 B2 16 1F D3 FD C5 59 D4 B6 78 46 1C EE 56 >
On 9/4/06, Rikard Johnels
I have this odd file filled with the remains of a psion-file that was corrupted. It seems fields are delimites with a $ sign. How can i quickly exchange those for a CR/LF combination ?
/me needs desperately to learn shell scripting and or Perl...
perl -i.bk -pe 's/\$/\r\n/g' filename.txt Should replace all occurences '$' with CR/LF combinations. If you only want the LF (unix style) then drop the '\r'. Your original file will be saved with a .bk extension. If you are confident that it's working and don't want the backup, drop the .bk as in : perl -i -pe 's/\$/\r\n/g' filename.txt HTH Marius
I'm curious, why use the perl command instead of just: sed 's/\$/\n/g' filename.txt > fixed.txt What exactly does perl -i -pe do different ? //Sylvester Marius Roets skrev:
On 9/4/06, Rikard Johnels
wrote: I have this odd file filled with the remains of a psion-file that was corrupted. It seems fields are delimites with a $ sign. How can i quickly exchange those for a CR/LF combination ?
/me needs desperately to learn shell scripting and or Perl...
perl -i.bk -pe 's/\$/\r\n/g' filename.txt
Should replace all occurences '$' with CR/LF combinations. If you only want the LF (unix style) then drop the '\r'. Your original file will be saved with a .bk extension. If you are confident that it's working and don't want the backup, drop the .bk as in :
perl -i -pe 's/\$/\r\n/g' filename.txt
HTH Marius
On 9/4/06, Sylvester Lykkehus
I'm curious, why use the perl command instead of just: sed 's/\$/\n/g' filename.txt > fixed.txt
What exactly does perl -i -pe do different ?
Well, nothing at all :). It's just a different way of doing the same thing. Personally I never bothered to learn sed or awk, quite simply because I could handle their functionality easily with perl. Perl has the added benefit of being quite a powerful and verstatile programming language. Marius
On 9/4/06, Marius Roets
I'm curious, why use the perl command instead of just: sed 's/\$/\n/g' filename.txt > fixed.txt
What exactly does perl -i -pe do different ?
Well, nothing at all :). It's just a different way of doing the same thing.
Actually I just thought of one difference. perl -i -pe 's/\$/\r\n/g' *.txt works just great, whilst the sed command would put it all in one file. Of course there are ways around it with a small shell script, I'm sure. Marius
Am Montag 04 September 2006 12:13 schrieb Sylvester Lykkehus:
I'm curious, why use the perl command instead of just: sed 's/\$/\n/g' filename.txt > fixed.txt
What exactly does perl -i -pe do different ?
'-i' means in-place-edit. There are versions of sed which also have this option, but not all. -- Viele Grüße ------------------------------------------------------------------------ Michael
The commands to do that are already on the system, at least on my system. I am not sure what package they came from but would be willing to investigate that is someone asks. /usr/bin/unix2dos /usr/share/doc/packages/unix2dos /usr/share/doc/packages/unix2dos/COPYRIGHT /usr/share/man/man1/unix2dos.1.gz /usr/bin/dos2unix /usr/share/doc/packages/dos2unix /usr/share/doc/packages/dos2unix/COPYRIGHT /usr/share/man/man1/dos2unix.1.gz
Robert Lewis schreef:
The commands to do that are already on the system, at least on my system. I am not sure what package they came from but would be willing to investigate that is someone asks.
(snip)
/usr/bin/unix2dos (snip) /usr/bin/dos2unix
No that wasn't OP's problem. unix2dos and dos2unix add/remove the extra CR (^M) at the end of a line in a text file. In OP's file all LF's had been replaced by '$' and that is a different kettle of fish. Regards, -- Jos van Kan registered Linux user #152704
Sylvester Lykkehus schreef: (Top posting reversed)
Marius Roets skrev:
On 9/4/06, Rikard Johnels
wrote: I have this odd file filled with the remains of a psion-file that was corrupted. It seems fields are delimites with a $ sign. How can i quickly exchange those for a CR/LF combination ?
/me needs desperately to learn shell scripting and or Perl...
(snip)
perl -i -pe 's/\$/\r\n/g' filename.txt
I'm curious, why use the perl command instead of just: sed 's/\$/\n/g' filename.txt > fixed.txt
What exactly does perl -i -pe do different ?
Nothing. But perl changes the file *in situ* whereas in sed you always need an auxiliary file to dump the output to. Regards, -- Jos van Kan registered Linux user #152704
Jos van Kan wrote:
Sylvester Lykkehus schreef: (Top posting reversed)
Marius Roets skrev:
On 9/4/06, Rikard Johnels
wrote: I have this odd file filled with the remains of a psion-file that was corrupted. It seems fields are delimites with a $ sign. How can i quickly exchange those for a CR/LF combination ?
/me needs desperately to learn shell scripting and or Perl...
(snip)
perl -i -pe 's/\$/\r\n/g' filename.txt
I'm curious, why use the perl command instead of just: sed 's/\$/\n/g' filename.txt > fixed.txt
What exactly does perl -i -pe do different ?
Nothing. But perl changes the file *in situ* whereas in sed you always need an auxiliary file to dump the output to.
Regards, Not completely true I think. For example sed -i 's/\$/\n/g' filename.txt
-i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if extension supplied) //Sylvester
On Monday 04 September 2006 19:02, Sylvester Lykkehus wrote:
Not completely true I think. For example sed -i 's/\$/\n/g' filename.txt
That only works with some versions of sed. (Recent GNU versions.) If you're on a Solaris machine, for example, sed -i won't work but perl -i will. -- ----- stephan@s11n.net http://s11n.net "...pleasure is a grace and is not obedient to the commands of the will." -- Alan W. Watts
On Mon, 2006-09-04 at 08:49 +0200, Rikard Johnels wrote:
I have this odd file filled with the remains of a psion-file that was corrupted. It seems fields are delimites with a $ sign. How can i quickly exchange those for a CR/LF combination ?
/me needs desperately to learn shell scripting and or Perl...
editpad has global search and replace functions, in fact a lot of simple text editors ought to, it's just a question of using them in hex-edit mode I think.
participants (8)
-
Jos van Kan
-
Marius Roets
-
Michael Behrens
-
Mike McMullin
-
Rikard Johnels
-
Robert Lewis
-
stephan beal
-
Sylvester Lykkehus