Map values of blocks in a single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Map values of blocks in a single line
# 8  
Old 12-28-2012
Hello rdrtx1, Thank youu! it works just perfect!

Just one last help if is possible.

If each command MGISP:IMSIS=XXX; after the ";" has the node name where was sent it the command, for example

<MGISP:IMSIS=80321;!MGCPTS 13!

I would like to add 2 more columns in the output (# and NODE) before the first column that now is IMSIS.:
1- First column that shows the count of each MGISP:IMSIS=XXX; found for each node name.
2- Second column that shows the node name found at the end of the command (the name in green between "!..!" in the example above, I mean MGCPTS 13)

So, if 10 MGISP where found for node XYZ, in the output, the column 1 should show 1,2,3..10 and column 2 will show the node name XYZ.

In this way, for the sample input attached, the output desired is:

Code:
#,NODE,IMSIS,M,NA,OBA,BO,PLMN,MAPVER,NRRG,CBA,CBAZ,CAMEL,INOPER,OWNMS,NATMS,ERIS,STALL
1,MGCPTS 13,99995626,6-77182,4,200,200,0,2,0,58,58,,121,,,,
2,MGCPTS 13,80321,5-44531,4,60,35,0,2,0,15,15,3,120,1,1,0,1
3,MGCPTS 13,29783,5-38889,4,200,200,0,2,0,18,18,0,,,,,
1,EXCH 214,53002,UNIDENTIFIED,,,,,,,,,,,,,,
1,MGCLS-05,942111,6-33313,4,150,49,0,2,0,22,22,3,,,,,
1,MGCLS-05,942123,6-889134,4,150,49,0,2,0,22,22,,,,,,
1,MGCLS-05,94201,5-777714,4,150,49,0,2,0,50,50,0,,,,,
2,MGCLS-05,2556798,5-44770,4,150,49,0,2,0,67,67,2,,,,,

If it is too much difficult to get column 1, please your help to add in the output the column for node name.

PS: I've highlighted in blue those lines to make more visible that the 3 series that begin with 942 appear with the same counter (1), because they are within the same command MGISP:IMSIS=942;. So, the counter increments to 2 in the next series (2556798) that corresponds to the same node MGCLS-05.

Many thanks again for any help.
# 9  
Old 12-29-2012
try:
Code:
awk '
BEGIN {
  z="#,NODE";
  s="IMSIS,M,NA,OBA,BO,PLMN,MAPVER,NRRG,CBA,CBAZ,CAMEL,INOPER,OWNMS,NATMS,ERIS,STALL";
  k=split(s,h,","); print z "," s;
}
$1 == "END" && c==0 {
  a[h[1]]=v; a[h[2]]="UNIDENTIFIED";
  printf cn[node] "," node ",";
  for (i=1; i<=k; i++) printf  (i<k) ? a[h[i]]",":a[h[i]]"\n";
  delete a;
}
!$1 && c==1 {
  if (a[h[1]]) {
    printf cn[node] "," node ",";
    for (i=1; i<=k; i++) printf  (i<k) ? a[h[i]]",":a[h[i]]"\n";
  }
  delete a;
}
/<..*;/ {++n; c=0; j=split($0,o,"[:=;!]"); w=o[j-4]; v=o[j-3]; node=o[j-1]; cn[node]++}
!$1 && c==0 {next}
$1 && c==1 {
  if (NF>1) for (i=1; i<=NF-1; i++) a[h[i]]=$i;
  f=v=$NF; x=sub("[-].*","", f); x=sub(".*[-]","", v);
  if (x) {a[f]=v} else {a[f]=1};
}
$1 == w {c=1}
' input2.txt

# 10  
Old 12-29-2012
Hello rdrtx1,

Works just perfect! Many thanks for your help.

Only is pending for me for the same input file but having MGISP:IMSIS=ALL; tabulate
the data, but I think I'll open a new thread related with this. I hope you can help me
because I think only would be needed to modify a bit your last code.

Thanks again so much!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Can I run repair on lot of blocks with single command ?

Hi, I have Solaris-10 OS on T5220. Both local disks were mirrored under SVM. Somehow when one disk gone bad (c0t1d0), other disk (c0t0d0) also got lot of bad block. We have readable data only on c0t0d0, but as soon as server comes after, it hangs when I run few commands because of read errors,... (1 Reply)
Discussion started by: solaris_1977
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

sed - filter blocks between single delimiters matching a pattern

Hi! I have a file with the following format:CDR ... MSISDN=111 ... CDR ... MSISDN=xxx ... CDR ... MSISDN=xxx ... CDR ... MSISDN=111 (2 Replies)
Discussion started by: Flavius
2 Replies

4. Shell Programming and Scripting

sed multiple multi line blocks of text containing pattern

Hi, I have a log file which has sessionids in it, each block in the log starts with a date entry, a block may be a single line or multiple lines. I need to sed (or awk) out the lines/blocks with that start with a date and include the session id. The files are large at several Gb. My... (3 Replies)
Discussion started by: andyatit
3 Replies

5. Shell Programming and Scripting

Row blocks to column blocks

Hello, Searched for a while and found some "line-to-column" script. My case is similar but with multiple fields each row: S02 Length Per S02 7043 3.864 S02 54477 29.89 S02 104841 57.52 S03 Length Per S03 1150 0.835 S03 1321 0.96 S03 ... (9 Replies)
Discussion started by: yifangt
9 Replies

6. Shell Programming and Scripting

Show distinct values of a key from a single line

Hi All, I am newbie to linux. Can somebody help me with following requirement. I have one huge line. I have to find out particular key/value pair to see the distinct value of that key. Portion of the String:- <?xml version="1.1" encoding="UTF-8"?> <Data><Val Ti="1342750845538" Du="0"... (5 Replies)
Discussion started by: kmajumder
5 Replies

7. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

8. Shell Programming and Scripting

How to map the values of an array in perl?

Hi, I have 2 arrays: @names=qw(amith veena chaitra); @files=qw(file.txt file1.txt file3.txt); There is one to one relationship between names and files. There needs to be mapping created between names and files. The output should be like this: amith --> file.txt veena --->... (3 Replies)
Discussion started by: vanitham
3 Replies

9. Shell Programming and Scripting

how to split this file into blocks and then send these blocks as input to the tool called Yices?

Hello, I have a file like this: FILE.TXT: (define argc :: int) (assert ( > argc 1)) (assert ( = argc 1)) <check> # (define c :: float) (assert ( > c 0)) (assert ( = c 0)) <check> # now, i want to separate each block('#' is the delimeter), make them separate files, and then send them as... (5 Replies)
Discussion started by: paramad
5 Replies

10. Shell Programming and Scripting

Find 5 lines and replace with 18 line in sql file where it contains multiple blocks.

My sql file xyz_abc.sql in this file there are multiple sql block in this block I need to find the following block rem Subset Rows (&&tempName.*) CREATE VIEW &&tempName.* AS SELECT * FROM &&tempName.* WHERE f is not null and replace with following code rem Subset Rows... (9 Replies)
Discussion started by: Zaheer.mic
9 Replies
Login or Register to Ask a Question