User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Feb 2007
Posts: 3
Reputation: avik1983 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
avik1983 avik1983 is offline Offline
Newbie Poster

Help Text file formatting by perl

  #1  
Feb 20th, 2007
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...
Last edited by avik1983 : Feb 20th, 2007 at 6:53 am.
Attached Files
File Type: txt good.txt (259 Bytes, 3 views)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: UK (Bristol)
Posts: 225
Reputation: Mushy-pea is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
Mushy-pea's Avatar
Mushy-pea Mushy-pea is offline Offline
Posting Whiz in Training

Re: Text file formatting by perl

  #2  
Feb 20th, 2007
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.
Hello, you're through to Steven on the BT Business technical help desk. Could I take your broadband telephone number please?
Reply With Quote  
Join Date: Jun 2005
Location: Tokyo, Japan
Posts: 1,480
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Rep Power: 8
Solved Threads: 98
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Text file formatting by perl

  #3  
Feb 22nd, 2007
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.
バルサミコ酢やっぱいらへんで
Reply With Quote  
Join Date: Feb 2007
Posts: 3
Reputation: avik1983 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
avik1983 avik1983 is offline Offline
Newbie Poster

Re: Text file formatting by perl

  #4  
Feb 22nd, 2007
i have done this already..thanks for helping
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Perl Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Perl Forum

All times are GMT -4. The time now is 9:29 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC