Character position


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Character position
# 1  
Old 10-25-2005
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  
Old 10-25-2005
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  
Old 10-25-2005
Works Great ... Thanks a lot Smilie
# 4  
Old 10-25-2005
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  
Old 10-26-2005
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Position of character in word

How can I represent the position of 1 (considering only the 1s after the colon) in the word from field5 and above; counting from right to left. Input: TT-124 06-03-14 08-02-10 FAS CAT1:10 TT-125-1 05-03-14 10-06-08 CAS CAT2:1010 FAT1:10000 TT-125-3 07-03-14 11-02-06 FAS FAT1:1101... (6 Replies)
Discussion started by: aydj
6 Replies

3. Shell Programming and Scripting

Find character and Replace character for given position

Hi, i want find the character '-' in a file from position 284-298, if it occurs i need to replace it with 'O ' for the position in the file. How to do that using SED command. thanks in advance, Sara (9 Replies)
Discussion started by: Sara183
9 Replies

4. Shell Programming and Scripting

Get character position within variable

Hi all let's say i have a file named 1234_v2_abcd i need to find the position of the character located after _v, in above case this would be character number 2 the count of the characters before _v can change, but i always have a number after _v can anybody help :) (4 Replies)
Discussion started by: gigagigosu
4 Replies

5. Shell Programming and Scripting

position of character in a line

i want to find the position of a character in a line , the first position, last, 5th occurence position , i ve tried grep -n , and expr index but they dont fit the bill. Please let me know if there is any other alternative (2 Replies)
Discussion started by: phpsnook
2 Replies

6. Shell Programming and Scripting

Extract a character specifying position

hi , i am having a file Full_ARTMAS_20110510152425.xml in my local directory. i wanted to extract the character at the 35143546 th position at line 1 of this file.Can any body help me how to do it??? regards Anjali (2 Replies)
Discussion started by: angel12345
2 Replies

7. Shell Programming and Scripting

Identify the position of character

Hi, Can some one guide me to identify the position of a character using index in UNIX. I have a record like "17/11/2010 15:16:39;reject;10.44.48.65;daemon alert; src: 10.44.48.112; dst: 172.21.52.88" . I need to identify the value which comes after _src:_ (_ denotes space). I am able to... (15 Replies)
Discussion started by: suneel.mekala
15 Replies

8. Shell Programming and Scripting

insert character in particular position.

I want to insert space in 7th position of all the lines usign vi editor or sed command Input file 12345689010 abcdefghijk . . Output file 123456 89010 abcdef ghijk . . (7 Replies)
Discussion started by: Jairaj
7 Replies

9. Shell Programming and Scripting

URG!! Last position of a character

Hi. If I have files with names like abcd.20080625.1234.abc.XYZ abcd.20080625.1234.abc.XYZW how can I get the XYZ or XYZW part? is there something like an Index() function but in reverse order? I was thinking that if I can get the position of the last dot... (7 Replies)
Discussion started by: mrodrig
7 Replies

10. UNIX for Advanced & Expert Users

Counting position of a character

Hi All, I have a file of the format : idsfskjvfdznvdfjvh ierwjfkncmvlkmc xszkmdvnosndzjndf weuhrndzierfncv rndsjnsllshens iernzkfndslkdhf zkinewfinfvlkmvd I wish to count the occurrences of character 'z' in the file. I also need to find out the position of 'z' in various lines. and... (3 Replies)
Discussion started by: rochitsharma
3 Replies
Login or Register to Ask a Question