LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-09-2004, 01:11 PM   #1
zero79
Member
 
Registered: Nov 2003
Location: Ohio
Distribution: Debian Unstable
Posts: 460

Rep: Reputation: 30
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.
 
Old 06-09-2004, 01:13 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
dos2unix is what you're looking for.
 
Old 06-09-2004, 02:02 PM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Maybe, just open the file with a linux editor like kwrite or vi and make some minor change, then save it.
 
Old 06-09-2004, 03:12 PM   #4
zero79
Member
 
Registered: Nov 2003
Location: Ohio
Distribution: Debian Unstable
Posts: 460

Original Poster
Rep: Reputation: 30
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.
 
Old 06-09-2004, 05:25 PM   #5
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

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

offers a way to convert the files using sed
 
Old 06-10-2004, 04:20 AM   #6
BigLarry
LQ Newbie
 
Registered: Jun 2004
Posts: 5

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

Any other ways of doing this.

Thanks

BL
 
Old 06-10-2004, 11:27 AM   #7
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
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.
 
Old 06-10-2004, 11:27 AM   #8
zero79
Member
 
Registered: Nov 2003
Location: Ohio
Distribution: Debian Unstable
Posts: 460

Original Poster
Rep: Reputation: 30
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.

Last edited by zero79; 06-10-2004 at 11:32 AM.
 
Old 06-11-2004, 03:00 AM   #9
BigLarry
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Rep: Reputation: 0
Cheers pees,

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

BL
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert DOS text files to UNIX text files ta0kira Linux - Software 7 03-15-2011 11:42 AM
How to convert binary text file from Windows marie@dk Linux - Software 2 10-12-2005 03:17 AM
Convert text files to html files lothario Linux - Software 3 09-27-2005 08:48 PM
convert CSV (TEXT) files to UTF-16 cccc Programming 1 07-01-2004 01:54 AM
MySQL: Convert Windows DB to *nix? carmstrong Linux - Software 1 05-18-2004 01:10 PM


All times are GMT -5. The time now is 02:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration