Batch converter of new line characters from unix to dos?

Все, что вы хотели знать о программизме, но боялись спросить.
Ответить
Аватара пользователя
Demurrage
Завсегдатай
Сообщения: 248
Зарегистрирован: 16 янв 2007, 12:47

Batch converter of new line characters from unix to dos?

Сообщение Demurrage »

I've got lots of files with the unix new line (CR) and need to convert them all to the dos new line (CR + LF).
Is there are batch utility to make it happen?
I know there are utilities to make such a conversion for an individual file e.g. dos2unix etc, but how about a batch utility?
CaptainBlack
Маньяк
Сообщения: 2063
Зарегистрирован: 07 июл 2008, 11:58
Откуда: Россия

Re: Batch converter of new line characters from unix to dos?

Сообщение CaptainBlack »

Demurrage писал(а):I've got lots of files with the unix new line (CR) and need to convert them all to the dos new line (CR + LF).
Is there are batch utility to make it happen?
I know there are utilities to make such a conversion for an individual file e.g. dos2unix etc, but how about a batch utility?
#!/bin/bash
for i in $( ls ); do
unix2dos $i
done

Под CMD/DOS напиши крохотный скрипт с командой FOR.
Аватара пользователя
sobomax
Маньяк
Сообщения: 3699
Зарегистрирован: 29 июн 2006, 22:53
Откуда: Vancouver

Re: Batch converter of new line characters from unix to dos?

Сообщение sobomax »

perl -pi -e 's|\n|\r\n|' /path/*.foo

-Maxim
Аватара пользователя
Demurrage
Завсегдатай
Сообщения: 248
Зарегистрирован: 16 янв 2007, 12:47

Re: Batch converter of new line characters from unix to dos?

Сообщение Demurrage »

Thanks, but had to write a little java program, because forgot to mention that the file structure was quite complex and I needed to recursively process all the folder & subfolders and process only ASCII files i.e. exclude binary files, so the algorithm wasn't that straightforward.
Ответить