i have a simple text file as input.i have to print that file in paragraph format.whenevr it finds "\n" in the input text it should start printing in next paragraph in output file.also a fixed amount of space should be given before start writing in every paragraph.
the input and output file format are attached below...
pls provide a unix ar perl script to do this...

Recommended Answers

All 3 Replies

Hi Avik. What you require is a program that replaces each instance of \n with \n\n. This could easily be done in Perl, but is so simple it would be neater to use sed. Seeing as you said a Unix script would be OK I'll assume you've got sed on your system and that you're in fact using a Unix system. In this case type the following into the shell:

cd /usr/bin
sed 's/\\n/\\n\\n/gw /path_to_file/new_file.txt' <good.txt

To add spaces before the start of each paragraph just add them to the end of the regex (between the first // block). If a mod reads this feel free to move it to the Unix scripts forum. I hope this helps.

Steven.

you should try this.

perl -p -i.bak -e 's/\\n/\n\n     /ig' good.txt

It edits the good.txt file and creates a good.txt.bak backup file. Remove the .bak part in the above command and the backup file wont be created.

i have done this already..thanks for helping

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.