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...

INPUT file:

i am avik.\n good boy.reading in school.loves math.have many friends.\n today joined this forum.

Output Format:
 i am avik.good boy.
   reading in school.loves 
 math.have many friends.
   today joined this forum.
10 Years
Discussion Span
Last Post by avik1983

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.



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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.