•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 391,555 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,624 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser:
Views: 3146 | Replies: 3 | Solved
![]() |
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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...
the input and output file format are attached below...
pls provide a unix ar perl script to do this...
Last edited by avik1983 : Feb 20th, 2007 at 6:53 am.
•
•
Join Date: Jun 2006
Location: UK (Bristol)
Posts: 225
Reputation:
Rep Power: 3
Solved Threads: 1
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:
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.
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.
Hello, you're through to Steven on the BT Business technical help desk. Could I take your broadband telephone number please?
•
•
Join Date: Jun 2005
Location: Tokyo, Japan
Posts: 1,480
Reputation:
Rep Power: 8
Solved Threads: 98
you should try this.
It edits the good.txt file and creates a
perl -p -i.bak -e 's/\\n/\n\n /ig' good.txt
good.txt.bak backup file. Remove the .bak part in the above command and the backup file wont be created. バルサミコ酢やっぱいらへんで
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Perl Marketplace
Similar Threads
- Extrace Pattern(E-mail ID) from text file (Perl)
- Compare two Text File (Perl)
- Beginner question: need help importing tab-delimited file as perl hash (Perl)
- Read and write to an ASCII Text file (Java)
- connect to text file database (Visual Basic 4 / 5 / 6)
Other Threads in the Perl Forum
- Previous Thread: HTML parsing by perl
- Next Thread: Difference between tr and s



Linear Mode