Format & re-arrange the records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format & re-arrange the records
# 1  
Old 01-07-2009
Format & re-arrange the records

Data on my input file :

Ac1n1s1c2n2s2XPd1r1e1t1d2r2e2t2d3r3e3t3d4r4e4t4RT
Bh1k1p1h2k2p2NTq1y1f1m1q2y2f2m2q3y3f3m3q4y4f4m4ZN

and i want the output to be:

Ac1n1s1XPd1r1e1t1RT
Ac1n1s1XPd2r2e2t2RT
Ac1n1s1XPd3r3e3t3RT
Ac1n1s1XPd4r4e4t4RT
Ac2n2s2XPd1r1e1t1RT
Ac2n2s2XPd2r2e2t2RT
Ac2n2s2XPd3r3e3t3RT
Ac2n2s3XPd4r4e4t4RT
Bh1k1p1NTq1y1f1m1ZN
Bh1k1p1NTq2y2f2m2ZN
Bh1k1p1NTq3y3f3m3ZN
Bh1k1p1NTq4y4f4m4ZN
Bh2k2p2NTq1y1f1m1ZN
Bh2k2p2NTq2y2f2m2ZN
Bh3k3p3NTq3y3f3m3ZN
Bh4k4p4NTq4y4f4m4ZN


Please help me how to format these records...thank you
# 2  
Old 01-07-2009
would you care to describe the 'algorithm' of your transformation, please.
# 3  
Old 01-08-2009
Code:
open FH,"a.txt";
while(<FH>){
	chomp;
	my @arr=(substr($_,0,1),substr($_,1,6),substr($_,7,6),substr($_,13,2),substr($_,15,8),substr($_,23,8),substr($_,31,8),substr($_,39,8),substr($_,47,2));
	for($j=1;$j<=2;$j++){
		for($i=4;$i<=7;$i++){
			print $arr[0].$arr[$j].$arr[3].$arr[$i].$arr[$#arr]."\n";
		}
	}
}

# 4  
Old 01-08-2009
#! /bin/ksh
open FH,"a.txt";
while(<FH>){
chomp;
my @arr=(substr($_,0,1),substr($_,1,6),substr($_,7,6),substr($_,13,2),substr($_,15,8),substr($_,23,8),s ubstr($_,31,8),substr($_,39,8),substr($_,47,2));
for($j=1;$j<=2;$j++){
for($i=4;$i<=7;$i++){
print $arr[0].$arr[$j].$arr[3].$arr[$i].$arr[$#arr]."\n";
}
}
}


i am getting the following error!!

dd_code.sh[2]: open: not found
dd_code.sh[3]: syntax error at line 3 : `)' unexpected


please advise...
# 5  
Old 01-08-2009
this is a 'perl' script, not a ksh script.
# 6  
Old 01-09-2009
format & re-arrange records

This works pretty well. can you explain me what is open "FH" , while"(<FH>)" and "CHOMP"..

thank you
# 7  
Old 01-09-2009
open FH,"a.txt";
while(<FH>){
chomp;
my @arr=(substr($_,0,1),substr($_,1,6),substr($_,7,6),substr($_,13,2),substr($_,15,8),substr($_,23,8),s ubstr($_,31,8),substr($_,39,8),substr($_,47,2));
for($j=1;$j<=2;$j++){
for($i=4;$i<=7;$i++){
print $arr[0].$arr[$j].$arr[3].$arr[$i].$arr[$#arr]."\n" > "b.txt";
}
}
}

from the above code i am trying to write the output in a file "b.txt".. i don't get any error messages but at the same time i don't see "b.txt" created...

can you help me to put /write these results in another file....

thanks in advance...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Playing with whois & dig - getting all the a records (globally)

Dear All, I want to get all the IPs of the A RECORDS for mail.google.com. The aim is to deny access to these IPs. I learnt that mail.google.com has several IPs. I did the following steps: 1. whois google.com 2. I got the following as its DOMAIN SERVERS: 3.# dig @ns1.google.com a... (1 Reply)
Discussion started by: coolatt
1 Replies

2. UNIX for Dummies Questions & Answers

How can I get certain records from this file format?

I have a file named: learn.999 that has the following format where each record is separated by ^M as follows: ... (11 Replies)
Discussion started by: mrn6430
11 Replies

3. Shell Programming and Scripting

Multiple records need to convert UNIXtime to human readable datatime and all output in one format

Hello Experts, Below is the record i have: sample data attached I want this record of each row to be in single line and there are multiple rowise unixtime mentioned e.g 11996327 , This needs to be converted to Human readdable data and time from multiple rows Can you help me , it will be... (10 Replies)
Discussion started by: manishK
10 Replies

4. Programming

Arrange word in table metrix format

Hello everyone, I have some problem about this code : #!/usr/bin/env python import sys try : filename = sys.argv except : print 'Specify filename' sys.exit() fd = open(filename) lines = fd.xreadlines() compare = {} for line in lines : split_line =... (1 Reply)
Discussion started by: awil
1 Replies

5. UNIX for Dummies Questions & Answers

Printing records in different format

Hi all, I have a input file say record.txt hostname IP_address Port_No Version A 10.10.10.1 80 6.02 B 10.10.10.2 81 6.03 C 10.10.10.3 82 6.04 row 1 has 4 field headings : hostname, IP_address, Port_No and Version. and from 2nd row onwards the actual records start. now i need to... (2 Replies)
Discussion started by: PranavEcstasy
2 Replies

6. Shell Programming and Scripting

script to arrange file in specific format

Hi All, I am new to forum, I am looking to arrange a file in specific format but unable to get the formula to do it, already googled for the same, but didnt find the answer :(. hope to get help here :o:o:o:o:o I have to files : $ cat Dev_List2 0685 0686 0687 0688 0689 068A 068B 068C... (2 Replies)
Discussion started by: prasan_Aix
2 Replies

7. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

8. Shell Programming and Scripting

Arrange / format data using awk

Input 217:fngadi4osa:fngadi4osa:M 217:415744:N/A 227:fngadi4osa:fngadi4osa: M 227:51200:N/A 228:fngadi4osa:fngadi4osa: M 228:102400:N/A 65:sapgt04:sapgt04: M 65:104448:N/A 228:fngadi4osa:fngadi4oma: M 228:102400:N/A Output 217:fngadi4osa:fngadi4osa:M 217:415744:N/A... (3 Replies)
Discussion started by: greycells
3 Replies

9. Shell Programming and Scripting

Sort & Split records in a file

Hi, I am new to scripting. I need a script to sort and the records in a file and then split them into different files. For example, the file is: H1...................... H2...................... D2.................... D2.................... H1........................... (15 Replies)
Discussion started by: Sunitha_edi82
15 Replies

10. Shell Programming and Scripting

gawk - reading two files & re arrange the columns

Hi, I am trying to read 2 files and writing to the 3rd file if I find the same elements in 2 files. my first file is 1 0 kb12124819 766409 1.586e-01 1 0 kb17160939 773886 8.674e-01 1 0 kb4475691 836671 8.142e-01 1 0 ... (2 Replies)
Discussion started by: ezhil01
2 Replies
Login or Register to Ask a Question