![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to split a value according to character position | michaeltravisuk | UNIX for Dummies Questions & Answers | 4 | 05-27-2008 04:07 AM |
| Counting position of a character | rochitsharma | UNIX for Advanced & Expert Users | 3 | 11-27-2007 03:26 PM |
| Change Position of word character | cedrichiu | Shell Programming and Scripting | 6 | 03-11-2007 10:52 PM |
| How to add character in specific position of a string? | victorlung | Shell Programming and Scripting | 5 | 09-01-2006 07:33 AM |
| Finding character position in file | dhananjaysk | Shell Programming and Scripting | 5 | 03-23-2006 08:49 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Character position
Hi ,
I am required to view the fixed postion file very often . I am looking for the utility like this if the file has a one or multile line abcdefghijklmnopqr Utility should make my file look like this 12345678910111213141516-------------------------- abcdefghijk l m n o p q r Any other suggestions is also also welcome . Thanks Ashok |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
This following code should me modifyable to your particular circumstances. save it in a file say called 'display.pl', make it executable and run it like
display.pl <your input file> Code:
#!/usr/local/bin/perl
# read in file
@data=<>;
# determine largest line in file
foreach $data (@data)
{
$max = length($data) if (length($data) > $max);
}
# how many actual digits in the number
$digits = length($max)+1;
# print out the heading
for ($i=0;$i<$max;$i++)
{
printf("%${digits}d",$i);
}
print "\n";
# print out the data
foreach $data(@data)
{
@line=split(//,$data);
foreach $char (@line)
{
printf("%${digits}s",$char);
}
}
print "\n";
|
|
#3
|
|||
|
|||
|
Works Great ... Thanks a lot
|
|
#4
|
|||
|
|||
|
Do you suggest any forum for perl where I can get questions and answers like this forum . Actually , I get a very few requirements where I have to use perl .
So thought of watching probably resolving some of the questions on the perl forum would make my perl little better . It's very difficult to enthu youself without having any real time requirement Thanks Ashok |
|
#5
|
|||
|
|||
|
www.perl.com
www.perl.org and the scripting forums on this BBS would be good starting positions. 5 minutes with google should allow you to find any number of perl resources. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|