- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Text to Paragraph conversion by perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2007 05:54 PM
тАО02-18-2007 05:54 PM
a)i have to print output as paragraph.actually when it finds an "\n" in the text file it should start writing(output)in next paragraph.and
b) before starting every paragraph it should
leave a fixed amount of space(same as "\t"),then it should start writing.
c)every line in the output file should not exceed a fixed position in the screen.
please write a script in perl to do this..its urgent.waitin for reply.
the example of output is given below:
I am a software professional.I am working in a software company.
The company is good.I have to work there fo
r for 8 hours.
Great job.My boss is Mr.xxx.Very good perso
n.......
look at the output...
**every line ending border is fixed.when it exceeds than previous one it come in next line
(like for in 2nd para and person in 3rd para)
**every paragraph starts with a definite amount of of space.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2007 06:02 PM
тАО02-18-2007 06:02 PM
Re: Text to Paragraph conversion by perl
(see attached file)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2007 11:59 PM
тАО02-18-2007 11:59 PM
Re: Text to Paragraph conversion by perl
> I am a software professional. I am working in a software company
> please write a script in perl to do this..its urgent
You have got to be kidding! No professional would ask someone else to do their work for them with the expectation of making their boss believe it was their's!
Buy some books; study them; and *try* yourself. Then, if you're stuck, post what you have tried and ask for help. If you can't or won't expend the effort, I urge you to find a new line of work.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 01:28 AM
тАО02-19-2007 01:28 AM
Re: Text to Paragraph conversion by perl
please have a look at the unix fmt command (man fmt) to get the fixed width.
The perl format function can be used to act upon the various controls (\n) etc.
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 04:51 PM
тАО02-19-2007 04:51 PM
Re: Text to Paragraph conversion by perl
but main problem is can't recognise the \n every time...only first time it does.
actually i can't print the every element of the text file individually.how to do that?
pls help...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 04:51 PM
тАО02-19-2007 04:51 PM
Re: Text to Paragraph conversion by perl
but main problem is can't recognise the \n every time...only first time it does.
actually i can't print the every element of the text file individually.how to do that?
pls help...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 07:22 PM
тАО02-19-2007 07:22 PM
Re: Text to Paragraph conversion by perl
sorry to see that my previous answer didn't really help (3 points).
Perhaps this will help:
#!/usr/bin/perl
$string="I\nam a software\n professional.\nI am";
$~ = "OUTLINE";
write;
format OUTLINE =
@*
$string
.
Will return:
I
am a software
professional.
I am
As per my first answer look at perl format command, as above and the unix fmt command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 08:29 PM
тАО02-19-2007 08:29 PM
Re: Text to Paragraph conversion by perl
thanks for helping.but actually i want to take a text file as input (not a string).then have to print in next paragraph whenever it gets a "\n" in that text file while reading it.
and the line width of output file should be fixed.
please help a little more if u can..i expect a little more from u Expert People
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 08:34 PM
тАО02-19-2007 08:34 PM
Re: Text to Paragraph conversion by perl
why don't you take my script, wrap it in some code to read through your file (line-by-line) to assign the read line to $string and then process as normal.
The output of this should be redirected to a file and then fmt with the -w option would reformat to the desired width.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 09:56 PM
тАО02-19-2007 09:56 PM
Re: Text to Paragraph conversion by perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 10:01 PM
тАО02-19-2007 10:01 PM
Re: Text to Paragraph conversion by perl
file attached
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 11:06 PM
тАО02-19-2007 11:06 PM
Re: Text to Paragraph conversion by perl
#!/usr/bin/perl
$string="I\nam a software\n professional.\nI am";
$~ = "OUTLINE";
write;
format OUTLINE =
@*
$string
.
after running the script output is:
sh monitor.sh
monitor.sh: line 2: =I\nam a software\n professional.\nI am: command not found
monitor.sh: line 3: $~: command not found
usage: write user [tty]
monitor.sh: line 5: format: command not found
monitor.sh: line 6: @*: command not found
monitor.sh: line 8: .: filename argument required
.: usage: . filename [arguments]
so what should i do?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 11:11 PM
тАО02-19-2007 11:11 PM
Re: Text to Paragraph conversion by perl
but can you help me running this script for a input text file..and how to format output page in fixed width.actually i dont know how to use the format command.
pls help me if you can..waitin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 11:14 PM
тАО02-19-2007 11:14 PM
Re: Text to Paragraph conversion by perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 11:37 PM
тАО02-19-2007 11:37 PM
Re: Text to Paragraph conversion by perl
we are so called 'experts' because we were willing to investigate and learn from suggestions, rather than just ask for finished solutions . I have provided all the building blocks you need to do the job.I feel more and more like James describes.
Use the internet for searches on perl scripts to read files etc. use "man frmt" for the unix format part.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 11:57 PM
тАО02-19-2007 11:57 PM
Re: Text to Paragraph conversion by perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2007 01:06 AM
тАО02-20-2007 01:06 AM
SolutionI agree 100% with the sentimen
ts expressed by JRF and Peter. Th
e only way to learn this, it to R
EAD and TRY.
However I must give you credit
for having provided input example
s and output examples, and the st
art of a solution.
What is missing is details in
the spec: line length, size of ta
b, real-tab or spaces? The sample
output does not seems to match t
he requirement either.
Below you'll find a possible s
olution. You may want to think of
adding a newline between paragra
phs, not breaking up words, and s
tarting words in a new line witho
ut a space.
And uh... how about signing wi
th a real name, preferably your o
wn?
Cheers,
Hein.
------------------- format.pl ----------
use warnings;
use strict;
my $line;
my $tab = " "; # Paragraph indent
my $max = 40; # Maximum line size
while (<>) { # read all input
s/^/$tab/; # Start line with tab
s/\\n/\n$tab/g; # Replace EOL marker with newline + tab
foreach $line (split /\n/) { # grab lines, which might be too long
while (length($line) > $max) {
print substr($line,0,$max) . "\n";
$line = substr($line,$max);
} # next chunk
print "$line\n"; # Final chunk of line
} # next line
} # next input
-------------------- usage sample -----
#perl format.pl \temp\tmp.txt
I am a software professional.I a
m working in a software company.
the company is good.i have to wo
rk there for 8 hours.
Great job.My boss is Mr.xxx.Very
good person
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2007 01:27 AM
тАО02-20-2007 01:27 AM
Re: Text to Paragraph conversion by perl
OK, under the assumption that you are serious, and in the spirit of this Forum, here's another solution. Consider this:
/*file_begins*/
Perl has a read-made soultion for you if you are willing to use it instead of a pure shell script. The Perl module you need is called Text::Wrap and it's included in you standard Perl distribution. In fact, you can use this very file to call it and show it reformatting. Let's reformat this into text that spans no more than 30-columns
and has it paragraphs indented four (4) spaces.
/*file_ends*/
Now, use this passing the name of the file with the above contents:
# perl -MText::Wrap -e '@lines=<>;$Text::Wrap::columns=30;print wrap(" ","",@lines)' file
Perl has a read-made
soultion for you if you are
willing to use it
instead of a pure shell
script. The Perl module you
need is called
Text::Wrap and it's included
in you standard Perl
distribution. In fact,
you can use this very file to
call it and show it
reformatting. Let's
reformat this into text that
spans no more than 30-columns
and has it paragraphs
indented four (4) spaces.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2007 05:26 PM
тАО02-20-2007 05:26 PM
Re: Text to Paragraph conversion by perl
that's why i always looking forward to you expert people.
thanks again..