BrandoN
BrandoN

Reputation: 313

Perl command to change file EOL and saving the file with the same name

I am using this perl command on my debian to change my file EOL:

perl -p -e 's/\n/\r\n/' < ~/scripts/bite/EOL/*.csv > ~/scripts/bite/sent/samefilename.csv

Every day there will be a new file in the "EOL" directory with a different name and it always has only 1 file in the directory, so I am using "*" to take whatever file is in it. But i need to save the new file with the same name as the file I chose to change without manually entering the file name to the command. Eventually this goes into my cronjob, so everything would be automatic.

EDIT: Fixed my problem by using "unix2dos"

Upvotes: 2

Views: 519

Answers (3)

bliako
bliako

Reputation: 1133

hmm @ikegami's answer adds an \r\n every time it is run. what if it is already encoded?

perl -pe's/([^\015]|^)\012/$1\015\012/g' -i file.csv

Upvotes: 0

Polar Bear
Polar Bear

Reputation: 6798

Linux has command unix2dos and dos2unix for converting eol from MS Windows/DOS to UNIX format. Perhaps it is easiest solution for described problem.

Upvotes: 2

ikegami
ikegami

Reputation: 385897

I would use the unix2dos utility, but you can also use

perl -pe's/\n/\r\n/' -i file.csv

See Specifying file to process to Perl one-liner.

Your program and this one only works on unix systems.

Upvotes: 2

Related Questions