Script needs to be modified - Each 5 Rows to be joined in single line with comma (,)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script needs to be modified - Each 5 Rows to be joined in single line with comma (,)
# 1  
Old 05-07-2008
Question Script needs to be modified - Each 5 Rows to be joined in single line with comma (,)

Hi All,

I'm using the following script to produce a result:

#!/bin/sh
awk ' $0 ~ /\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+Interface\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+/ {
match_str="YES"; line_cnt=0; next; }
{
if((line_cnt < 5) && ( match_str=="YES"))
{
print $0;
line_cnt += 1;
}
else {
match_str="NO"; line_cnt=0; }
}' InputFileName

I'm getting the following result:

IFName: aust00m1.mis.amat.com[ 0 [ 257 ] ]
ObjID: 5eceea48-0d59-71dd-1512-9887a1f10000
IFAlias: Dest: AMNA austkchr1-ser0/0/0:0.315 Type: FRASI CID: DHEC.559128
IFDescription: ATM9/1/0.315-atm subif
Status: Normal
IFName: aust00m1.mis.amat.com[ 0 [ 258 ] ]
ObjID: 5ed18d98-0d59-71dd-1512-9887a1f10000
IFAlias: Dest: AMNA austkchr1-ser0/0/0:0.315 Type: FRASI CID: DHEC.559128
IFDescription: ATM9/1/0.315-aal5 layer
Status: Normal
IFName: aust00m1.mis.amat.com[ 0 [ 259 ] ]
ObjID: 5ed53358-0d59-71dd-1512-9887a1f10000
IFAlias: Dest: AMNA austkchr1-ser0/0/1:0.325 Type: FRASI CID: DHEC.531638
IFDescription: ATM9/1/0.325-atm subif
Status: Normal

I want to convert Each 5 Rows to 5 Columns separated with , (comma).

IFName: aust00m1.mis.amat.com[ 0 [ 257 ] ],ObjID: 5eceea48-0d59-71dd-1512-9887a1f10000,IFAlias: Dest: AMNA austkchr1-ser0/0/0:0.315 Type: FRASI CID: DHEC.559128,IFDescription: ATM9/1/0.315-atm subif,Status: Normal

IFName: aust00m1.mis.amat.com[ 0 [ 258 ] ],ObjID: 5ed18d98-0d59-71dd-1512-9887a1f10000,IFAlias: Dest: AMNA austkchr1-ser0/0/0:0.315 Type: FRASI CID: DHEC.559128,IFDescription: ATM9/1/0.315-aal5 layer,Status: Normal

I have modify the above script according to my requirement. Pls. anybody help me out.

Thanks,
Gobinathan.S
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to check line end not ending with comma

I have several line in a text file. for example I like apple; I like apple I like orange; Output: I like apple I try to useif grep -q "!\;$"; then (Not work) Please use CODE tags when displaying sample input, sample output, and code segments (as required by forum rules). (1 Reply)
Discussion started by: cmdcmd
1 Replies

2. Shell Programming and Scripting

Bring values in the second column into single line (comma sep) for uniq value in the first column

I want to bring values in the second column into single line for uniq value in the first column. My input jvm01, Web 2.0 Feature Pack Library jvm01, IBM WebSphere JAX-RS jvm01, Custom01 Shared Library jvm02, Web 2.0 Feature Pack Library jvm02, IBM WebSphere JAX-RS jvm03, Web 2.0 Feature... (10 Replies)
Discussion started by: kchinnam
10 Replies

3. Shell Programming and Scripting

Insert single quote on every word separated by comma

Hello, I have a text file as:-ABC BCD CDF DEF EFGI need to convert as 'ABC', 'BCD', 'CDF', 'DEF', 'EFG' using a unix command anybody can help me out on this. Regards, Jas Please wrap all code, files, input & output/errors in CODE tags. It makes them easier to read and preserves... (12 Replies)
Discussion started by: jassi10781
12 Replies

4. Shell Programming and Scripting

Transpose comma delimited data in rows to columns

Hello, I have a bilingual database with the following structure a,b,c=d,e,f The right half is in a Left to right script and the second is in a Right to left script as the examples below show What I need is to separate out the database such that the first word on the left hand matches the first... (4 Replies)
Discussion started by: gimley
4 Replies

5. Shell Programming and Scripting

Comma separated to rows based on field

Hi to all, I have a file like: chr1 a1 a2 a3 a4 a5 a6,a7,a8,a9 chr1 b1 b2 b3 b4 b5 b6,b7 chr2 c1 c2 c3 c4 c5 c6,c7,c8,c9,c10 ... I would like an output like this: chr1 a6 chr1 a7 chr1 a8 chr1 a9 chr1 b6 chr1 b7 chr2 c6 chr2 c7 chr2 c8 (6 Replies)
Discussion started by: aec
6 Replies

6. Shell Programming and Scripting

How to grep after the first comma till the next comma in a line

Hi Can any one pls tell me how to grep this line POPULATION,69691,20120509 I want the number 69691 from the above line. How to grep from the first comma till the next comma. Thank You.:confused: (8 Replies)
Discussion started by: rxg
8 Replies

7. Shell Programming and Scripting

Comma delimited row into multiple rows, repeat first value

i am building a database to keep track of unix groups. Using the command "ypcat group" I get an output similar to the following group1:GROUP:9999:user1,user2,user3 groupA:GROUP:1111:usera,userb,userc I want to convert this output so it looks like this group1:user1 group1:user2... (2 Replies)
Discussion started by: newreverie
2 Replies

8. Shell Programming and Scripting

shell script - to append single quotes and comma

file1 ---- 34556745 32678343 31576776 31455566 21356666 I want to assign the record values to a variable in the below format, so that I can use output in .sql file for querying in database. ('34556745', '32678343', '31576776', '31455566', '21356666') ----------- below is the... (11 Replies)
Discussion started by: rajivrsk
11 Replies

9. Shell Programming and Scripting

Split single rows to multiple rows ..

Hi pls help me out to short out this problem rm PAB113_011.out rm: PAB113_011.out: override protection 644 (yes/no)? n If i give y it remove the file. But i added the rm command as a part of ksh file and i tried to remove the file. Its not removing and the the file prompting as... (7 Replies)
Discussion started by: sri_aue
7 Replies

10. Shell Programming and Scripting

Remove comma and next rows beginning from the end

Hello friends, I have a file which consists of many rows, I use a couple of commands to convert it so i can use in a database query for filtering. I need the first columns (msisdns) in a row, seperated with commas, 9855162267,4,5,2010-11-03 17:02:07.627 9594567938f,5,5,2010-11-02... (9 Replies)
Discussion started by: EAGL€
9 Replies
Login or Register to Ask a Question