![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Text formatting in Perl. | fenox | Shell Programming and Scripting | 2 | 02-15-2008 12:06 PM |
| Perl Sort on Text File | eltinator | Shell Programming and Scripting | 6 | 08-07-2007 11:20 AM |
| Formatting a text file based on newline and delimiter characters | ntekupal | Shell Programming and Scripting | 5 | 05-11-2007 12:33 PM |
| Perl text file | Sn33R | Shell Programming and Scripting | 5 | 10-31-2003 07:59 AM |
| Perl: taking text from a .txt file | perleo | Shell Programming and Scripting | 2 | 06-19-2003 07:23 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
text file formatting by perl
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... |
| Forum Sponsor | ||
|
|
|
|||
|
What have you tried so far ?
Code:
#! /opt/third-party/bin/perl
my($data);
open ( FILE, "< inputfile " ) || die "Unable to open file 'inputfile' <$!> \n";
open ( OUTFILE, "> outputfile " ) || die "Unable to open file 'outputfile' <$!> \n";
while ( read(FILE, $data, 1) == 1 ) {
if( $data eq "\\" ) {
if( read(FILE, $data, 1) == 1 ) {
if( $data eq "n" ) {
print OUTFILE "\n";
next;
}
else {
print OUTFILE "\\$data";
next;
}
}
else {
last;
}
}
print OUTFILE "$data";
}
close (FILE);
close (OUTFILE);
exit 0
|
|
|||
|
thanks..workin(but a little more plss..)
many many thanks....
now can you give me solution how to print the output... the output file always should have a fixed width.means the space for characters in each line should be of same length output file format is attached.(take it just as example..it should be like this) look at the 2nd and 3rd line where words r still not completed but the remaining part is written in next line to maintain the fixed line width of output file.. can u help me in this regards...what else to join in ur script. |
|
|||
|
Code:
#! /opt/third-party/bin/perl
my($data, $MAXCHAR_IN_LINE, $cnt);
$MAXCHAR_IN_LINE = 10;
open ( FILE, "< a" ) || die "Unable to open file 'a' <$!> \n";
open ( OUTFILE, "> b" ) || die "Unable to open file 'b' <$!> \n";
while ( read(FILE, $data, 1) == 1 ) {
if( $cnt == $MAXCHAR_IN_LINE ) {
$cnt = 0;
print OUTFILE "\n";
}
else {
$cnt++;
}
if( $data eq "\\" ) {
if( read(FILE, $data, 1) == 1 ) {
if( $data eq "n" ) {
print OUTFILE "\n";
next;
}
else {
print OUTFILE "\\$data";
next;
}
}
else {
last;
}
}
print OUTFILE "$data";
}
close (FILE);
close (OUTFILE);
exit 0
|
| Thread Tools | |
| Display Modes | |
|
|