The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-25-2005
akrathi akrathi is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 41
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
  #2 (permalink)  
Old 10-25-2005
Unbeliever Unbeliever is offline
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";
  #3 (permalink)  
Old 10-25-2005
akrathi akrathi is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 41
Works Great ... Thanks a lot
  #4 (permalink)  
Old 10-25-2005
akrathi akrathi is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 41
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 (permalink)  
Old 10-26-2005
Unbeliever Unbeliever is offline
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0