Operating System - Linux
1748128 Members
3579 Online
108758 Solutions
New Discussion юеВ

Re: Perl text formating help

 
SOLVED
Go to solution
Shaf_1
Advisor

Perl text formating help

Hello,

I have a bunch of text files that are messed up when I open them up in word. Is there a way in perl to format the txt file so that it appears in word correctly. Please see the attahed file in MS word to see that the formating of the txt file is messed up.

Below is a part of the file and you can see that the carriage returns are the problem.

Is there a way to fix this?

Thanks For the help.



Dear Mr.,

Mercury pollution from power plants poses a serious threat to pregnant
women,
fetuses, and children. It causes learning disabilities and other
neurological
disorders.

The Clean Air Act requires the EPA to set limits on hazardous power-plant
pollution
such as mercury, taking into account the maximum reductions that are
achievable
using current technology. The EPA said it could require a 90% reduction in
mercury
6 REPLIES 6
John Poff
Honored Contributor
Solution

Re: Perl text formating help

Hi,

Give this a try (assuming you are running Linux):

fmt 161950.txt

The 'fmt' command is a simple text reformatter and should reformat your text file.

JP
Shaf_1
Advisor

Re: Perl text formating help

Hello JP,

Does the new formated version get saved as the same file name? I ran the command fmt 98788.txt and opened the file in MS word after word. The text is still the same as before. With this command should the document come up in word correctly?

Thanks
John Poff
Honored Contributor

Re: Perl text formating help

You'll have to redirect the output to another filename, like this:

fmt 161950.txt >161950.new.txt

or something like that. If you want to replace the original file with the new one, you'll have to rename it (after making sure the new file is what you want)

mv 161950.new.txt 161950.txt

JP
Shaf_1
Advisor

Re: Perl text formating help

Hello JP,

You are a life saver. I have one more question. How could I run the command for a bunch of files at once where the files will be formated and saved?

Thanks
John Poff
Honored Contributor

Re: Perl text formating help

Try something like this:

for f in *.txt
do
fmt $f >${f}.new
mv $f.new $f
done


Replace the '*.txt' with whatever filespec that matches the files you need to work on.

Have fun!

JP
Shaf_1
Advisor

Re: Perl text formating help

Thank you so much for all your help.