![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| 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 07:07 AM |
| Counting position of a character | rochitsharma | UNIX for Advanced & Expert Users | 3 | 11-27-2007 06:26 PM |
| Change Position of word character | cedrichiu | Shell Programming and Scripting | 6 | 03-12-2007 01:52 AM |
| How to add character in specific position of a string? | victorlung | Shell Programming and Scripting | 5 | 09-01-2006 10:33 AM |
| Finding character position in file | dhananjaysk | Shell Programming and Scripting | 5 | 03-23-2006 11:49 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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";
|
|
||||
|
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 |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|