The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-25-2005
Registered User
 

Join Date: Sep 2005
Posts: 36
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
Reply With Quote
Forum Sponsor
  #2  
Old 10-25-2005
Registered User
 

Join Date: Jul 2005
Location: England
Posts: 183
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";
Reply With Quote
  #3  
Old 10-25-2005
Registered User
 

Join Date: Sep 2005
Posts: 36
Works Great ... Thanks a lot
Reply With Quote
  #4  
Old 10-25-2005
Registered User
 

Join Date: Sep 2005
Posts: 36
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
Reply With Quote
  #5  
Old 10-26-2005
Registered User
 

Join Date: Jul 2005
Location: England
Posts: 183
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0