LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to convert windows formatted text files to *nix formatting? (https://www.linuxquestions.org/questions/linux-general-1/how-to-convert-windows-formatted-text-files-to-%2Anix-formatting-191569/)

zero79 06-09-2004 01:11 PM

how to convert windows formatted text files to *nix formatting?
 
Hi all,

I have a text file created in Windows with the following format

Code:

<name1> <number1>
<name2> <number2>
  .        .
  .        .
  .        .

I want to be able to parse out the <number> values from the file via a bash script. I have created a script

Code:

#!/bin/bash
file="/home/test/file.txt"
cat ${file} | \
while read name num
do
sum=$(($sum + $num ))
echo "$sum"
done

which works well on a text file with the above format created in linux, but does not work on a text file created in windows. So, how do I go about converting a windows formatted text file to *nix format? Something that could be done in bash is the optimum solution for me.

Thanks for any help.

Dark_Helmet 06-09-2004 01:13 PM

dos2unix is what you're looking for.

homey 06-09-2004 02:02 PM

Maybe, just open the file with a linux editor like kwrite or vi and make some minor change, then save it.

zero79 06-09-2004 03:12 PM

thanks dark_helmet, you rule.

homey, thanks also, but i gotta go thru a massive amount of these files, so it would be rough to do it by hand.

SciYro 06-09-2004 05:25 PM

http://www-106.ibm.com/developerwork...ry/l-sed3.html

offers a way to convert the files using sed

BigLarry 06-10-2004 04:20 AM

I think I have the same problem :/ only the SED script wouldn't work for me :(

Any other ways of doing this.

Thanks

BL

Dark_Helmet 06-10-2004 11:27 AM

Again: dos2unix

It's a program you run from the command line. man dos2unix to read about it. If you tried it and had errors, then please post them.

zero79 06-10-2004 11:27 AM

Code:

dos2unix -n windows.txt unix.txt
worked for me. The sed command that sciyro linked to is to convert a unix text file to windows. So you would need to modify the statement accordingly to go the opposite way.

edit: oh, i guess there is a sed example there to convert from windows to unix format also. my bad.

BigLarry 06-11-2004 03:00 AM

Cheers pees,

I installed tofrodos and was able to add that into my script and it worked fine!!

BL


All times are GMT -5. The time now is 01:43 PM.