script to arrange file in specific format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to arrange file in specific format
# 1  
Old 08-13-2012
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 Smilie. hope to get help here SmilieSmilieSmilieSmilieSmilie

I have to files :
Code:
$ cat Dev_List2
0685
0686
0687
0688
0689
068A
068B
068C
068D
068E
068F
0690
0691
0692
0693
0694
0695
0696
0697
0698
0699
069A
$ cat Dev_Meta_Member
2
4
8
4
2
2

I want to arrange this file in specific format i.e
Template :
Code:
form meta from dev XXXX, config=STRIPED;
add dev XXXX to meta XXXX;

i.e

Code:
form meta from dev 0685, config=STRIPED;
add dev 0686 to meta 0685;
form meta from dev 0687, config=STRIPED;
add dev 0688 to meta 0687;
add dev 0689 to meta 0687;
add dev 068A to meta 0687;
form meta from dev 068B, config=STRIPED;
 add dev 068C to meta 068B;
  add dev 068D to meta 068B;
  add dev 068E to meta 068B;
  add dev 068F to meta 068B;
  add dev 0690 to meta 068B;
 add dev 0691 to meta 068B;
 add dev 0692 to meta 068B;
form meta from dev 0693, config=STRIPED;
 add dev 0694 to meta 0693;
 add dev 0695 to meta 0693;
 add dev 0696  to meta 0693;
form meta from dev 0697, config=STRIPED;
 add dev 0698 to meta 0697;
form meta from dev 0699, config=STRIPED;
 add dev 069A to meta 0699;

Please revert, if you need more details on this.


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-13-2012 at 06:27 AM.. Reason: code tags
# 2  
Old 08-13-2012
Code:
awk '{
for(i=1;i<=$0;i++)
{
 getline rec < "Dev_List2"
 if(i==1)
 {
  first=rec
  print "form meta from dev " rec ", config=STRIPED;"
  continue
 }
 print "add dev " rec " to meta " first ";"
}
}' Dev_Meta_Member

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 08-13-2012
Wohhhhh....

I was looking for this from past two weeks & cant google it & it took just 5 min to get the code here.


thanks aton elixir_sinari .

i will now make the rest of the script.

This piece of code has reduce my work from 2 hours to 10 min or less.SmilieSmilieSmilieSmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting text files to xls through awk script for specific data format

Dear Friends, I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls. The input is as follows: >gi|1234|ref| Query = 1 - 65, Target = 1677 - 1733 Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46 fd sdfsdfsdfsdf fsdfdsfdfdfdfdfdf... (6 Replies)
Discussion started by: Amit1
6 Replies

2. Shell Programming and Scripting

Copy UNIX File into a DSN with a specific Format

Hi All , I am new to programming and here is what i am trying to achieve , i am taking a list of mounted filesystems (based on the HLQ) , passing it on to a txt file and then copying the file to a DSN .The code i am using : df | grep WAST.*WASCFG.*ZFS | awk '{print $2}' | sort -o log.txt |... (5 Replies)
Discussion started by: AnjanM
5 Replies

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

4. Shell Programming and Scripting

Extracting content from a file in specific format

Hi All, I have the file in this format **** Results Data **** Time or Step 1 2 20 0.000000000e+00 0s 0s 0s 1.024000000e+00 Us 0s 0s 1.100000000e+00 1s 0s 0s 1.100000001e+00 1s 0s 1s 2.024000000e+00 Us Us 1s 2.024000001e+00 ... (7 Replies)
Discussion started by: diehard
7 Replies

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

6. Shell Programming and Scripting

How to check for file name of specific format using find?

I have to find the specific formatted file is present in the received list in the directory, for which I have written: file_list=`ls -lrt /tmp/vinay/act/files |grep "$cdate"| awk '{print $9}'` while read fileStr do find $file_list $fileStr > /dev/null status=`echo $?` if ; then ... (3 Replies)
Discussion started by: IND123
3 Replies

7. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

8. Shell Programming and Scripting

shell script to format file based on specific patterns

Please help me out and drag me out the deadlock I am stuck into: I have a file. I want the statements under a if...then condition be listed in a separate file in the manner condition|statement.Following are the different input pattern and corresponding output parameters.any generic code to... (7 Replies)
Discussion started by: joyan321
7 Replies

9. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: rlmadhav
6 Replies

10. Shell Programming and Scripting

extract specific data from xml format file.

Hi, I need to extract the start time value (bold, red font) under the '<LogEvent ID="Timer Start">' tag (black bold) from a file with the following pattern. There are other LogEventIDs listed in the file as well, making it harder for me to extract out the specific start time that I need. . .... (7 Replies)
Discussion started by: 60doses
7 Replies
Login or Register to Ask a Question