Copy data to CSV file from txt output

Hi Everyone ,

Below is output from a TL1 , I want just the NE Name: and beside that the Temperature and the voltages in a csv file , Is this possible?


> act-user:AB1S2a:ArshadFO:493::**********;

   AB1S2a 2016-02-07 10:13:24
M  493 COMPLD
   "ArshadFO:2016-02-07 10-04-55,0"
;

   AB1S2a 2016-02-07 10:13:24
A  0 REPT EVT SESSION
   "AB1S2a:NO,"
   /* TL1 Agent Copyright (c) 1999-2007 Cisco Systems, Inc.


   QR3S2a 2016-02-07 10:34:53
A  0 REPT EVT SESSION
   "QR3S2a:NO,"
   /*

      User ArshadFO logged in from 172.17.11.72 */
;

   QR3S2a 2016-02-07 10:34:55
M  1 COMPLD
   ":SHELF,TEMPERATURE=24C,VOLTAGEA=53950,VOLTAGEB=53905,"
;
> 

   QR3S2a 2016-02-07 10:34:55
M  123 COMPLD
;

There is no NE Name: in any of seven different versions of your post to this point. Using the NE name: data from an earlier version of your post, you could try something like:

awk '
/NE name:/ {
	n = $4
}
/:SHELF,/ {
	split($0, t, /[=,]/)
	print n, t[3], t[5], t[7]
}' OFS=, file

producing the output:

AB1S2a,33C,54446,54418
AB2S2a,27C,54158,54119
NJRS2c,25C,54232,54244
QH1S2a,25C,53574,53572
QH2S2a,29C,54438,54484
QH3S2a,32C,54360,54391
QR1S2a,35C,54241,54223
QR2S2a,24C,54309,54250
QR3S2a,24C,53950,53905

from the sample data you had provided at that point.

Of course, I have no idea how to extract NE name: data from your current sample input file. So, this might or might not be of any use to you.

If you want to try this script with an earlier sample of your data on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .

1 Like

Hi thanks for reply below is the proper code ,

I want the NE name which is AB1S2a and the Temperature which is 33C to be able output in csv.

### NE name: AB1S2a ###

> RTRV-SHELFSTAT:AB1S2a::1;

   AB1S2a 2016-02-07 13:18:14
M  1 COMPLD
   ":SHELF,TEMPERATURE=33C,VOLTAGEA=54446,VOLTAGEB=54442,"
;


### NE name: AB4S2a ###

> RTRV-SHELFSTAT:AB2S2a::1;

   AB1S2a 2016-02-07 13:18:14
M  1 COMPLD
   ":SHELF,TEMPERATURE=33C,VOLTAGEA=54446,VOLTAGEB=54442,"

So, with your new input and your new output format requirement (without the voltages that were required in your 1st post), can you guess at how to modify the script I suggested in post #2 in this thread to get the output you now say you want?

Thanks you very much got it to work but the output is replacing the echo output at the start of the script

#!/bin/bash


i=output.csv

echo "NE_Name, Temperature" >$i


awk '
/NE name:/ {
        n = $4
}
/:SHELF,/ {
        split($0, t, /[=,]/)
        print n, t[3], t[5], t[7], t[9], t[11]
}' OFS=, /cygdrive/c/output/test1/sdh.txt >$i


Use "append redirection" >> . Or, don't echo but print the header first thing in the awk script.

---------- Post updated at 12:19 ---------- Previous update was at 12:17 ----------

And , don't forget the voltages in the header.

---------- Post updated at 12:21 ---------- Previous update was at 12:19 ----------

And, not clear why you print t[9] and t[11] when there's 7 elements in a sample line only.

OK. So you want a header line that provides headings for the 1st two of your six output fields and you want a <comma><space> separator between fields in the header line and a <comma> separator in the data lines. And, the data in your real input file must have temperature, voltages, and two more fields you didn't show us before. These all seem strange to me, but if that is what you want that is fine.

To append the output from the awk command to your output file instead of overwriting it, change the last line of your script from:

}' OFS=, /cygdrive/c/output/test1/sdh.txt >$i

to:

}' OFS=, /cygdrive/c/output/test1/sdh.txt >>$i

Thanks Don the two other fields are also voltages like the output is very long and i am trying figure out bit by bit.

It was really helpful as i am new to bash scripting.

---------- Post updated at 06:49 AM ---------- Previous update was at 06:43 AM ----------

And in the same output i have multiple shelfs and i want the same NE name to be printed beside for the multiple shelfs and adding one column shelf .

### NE name: AZID1a ###

Trying 172.17.23.132...


   AZID1a 2016-02-03 20:55:30
M  1 COMPLD
   "SHELF-1:SHELF,TEMPERATURE=24C,VOLTAGEA=53034,VOLTAGEB=53402,"
   "SHELF-2:SHELF,TEMPERATURE=26C,VOLTAGEA=53375,VOLTAGEB=53504,"
   "SHELF-3:SHELF,TEMPERATURE=22C,VOLTAGEA=52907,VOLTAGEB=53300,"


spawn telnet 172.17.39.4 3083

### NE name: DAND1b ###

Trying 172.17.39.4...

;
> 
> RTRV-SHELFSTAT:DAND1b::1;

   DAND1b 2016-02-03 20:56:58
M  1 COMPLD
   "SHELF-1:SHELF,TEMPERATURE=25C,VOLTAGEA=53781,VOLTAGEB=53754,"
   "SHELF-2:SHELF,TEMPERATURE=21C,VOLTAGEA=54188,VOLTAGEB=54153,"
   "SHELF-3:SHELF,TEMPERATURE=25C,VOLTAGEA=53838,VOLTAGEB=53926,"
   "SHELF-4:SHELF,TEMPERATURE=21C,VOLTAGEA=53816,VOLTAGEB=53870,"
   "SHELF-5:SHELF,TEMPERATURE=24C,VOLTAGEA=54095,VOLTAGEB=54082,"
   "SHELF-6:SHELF,TEMPERATURE=20C,VOLTAGEA=54081,VOLTAGEB=54106,"
   "SHELF-7:SHELF,TEMPERATURE=34C,VOLTAGEA=52528,VOLTAGEB=53551,"
   "SHELF-8:SHELF,TEMPERATURE=34C,VOLTAGEA=52129,VOLTAGEB=52597,"
   "SHELF-9:SHELF,TEMPERATURE=29C,VOLTAGEA=53840,VOLTAGEB=53870,"
   "SHELF-10:SHELF,TEMPERATURE=25C,VOLTAGEA=53946,VOLTAGEB=53902,"
   "SHELF-11:SHELF,TEMPERATURE=30C,VOLTAGEA=53890,VOLTAGEB=53879,"
   "SHELF-12:SHELF,TEMPERATURE=25C,VOLTAGEA=53121,VOLTAGEB=53126,"
   "SHELF-13:SHELF,TEMPERATURE=25C,VOLTAGEA=53693,VOLTAGEB=53726,"
   "SHELF-14:SHELF,TEMPERATURE=24C,VOLTAGEA=54093,VOLTAGEB=54072,"
   "SHELF-15:SHELF,TEMPERATURE=22C,VOLTAGEA=53749,VOLTAGEB=53783,"
;


The code I suggested before was giving you the two voltages from your prior input format...

If you keep changing you input format, and never show us exactly what output you're trying to produce, we're just making wild guesses. (Are you trying to extract SHELF-x for the shelf field (where x is the shelf number) or are you trying to just extract x?)

Please show us the actual output you are hoping to produce from your latest input sample.

What is there is the code that I suggested in this thread and that RudiC suggested in your other thread that you can't figure out how it is working by reading the awk man page on your system while looking at our code?

1 Like

Hi Don,

This is different output format which was in my first post i was trying to get the temperature and the voltages and that was solved thanks to you ,In this output i need the shelf number , temperature and voltages but the first column should be the same NE Name for output criteria.

### NE name: AZID1a ###

Trying 172.17.23.132...


   AZID1a 2016-02-03 20:55:30
M  1 COMPLD
   "SHELF-1:SHELF,TEMPERATURE=24C,VOLTAGEA=53034,VOLTAGEB=53402,"
   "SHELF-2:SHELF,TEMPERATURE=26C,VOLTAGEA=53375,VOLTAGEB=53504,"
   "SHELF-3:SHELF,TEMPERATURE=22C,VOLTAGEA=52907,VOLTAGEB=53300,"


spawn telnet 172.17.39.4 3083

### NE name: DAND1b ###

Trying 172.17.39.4...

;
> 
> RTRV-SHELFSTAT:DAND1b::1;

   DAND1b 2016-02-03 20:56:58
M  1 COMPLD
   "SHELF-1:SHELF,TEMPERATURE=25C,VOLTAGEA=53781,VOLTAGEB=53754,"
   "SHELF-2:SHELF,TEMPERATURE=21C,VOLTAGEA=54188,VOLTAGEB=54153,"
   "SHELF-3:SHELF,TEMPERATURE=25C,VOLTAGEA=53838,VOLTAGEB=53926,"
   "SHELF-4:SHELF,TEMPERATURE=21C,VOLTAGEA=53816,VOLTAGEB=53870,"
   "SHELF-5:SHELF,TEMPERATURE=24C,VOLTAGEA=54095,VOLTAGEB=54082,"
   "SHELF-6:SHELF,TEMPERATURE=20C,VOLTAGEA=54081,VOLTAGEB=54106,"
   "SHELF-7:SHELF,TEMPERATURE=34C,VOLTAGEA=52528,VOLTAGEB=53551,"
   "SHELF-8:SHELF,TEMPERATURE=34C,VOLTAGEA=52129,VOLTAGEB=52597,"
   "SHELF-9:SHELF,TEMPERATURE=29C,VOLTAGEA=53840,VOLTAGEB=53870,"
   "SHELF-10:SHELF,TEMPERATURE=25C,VOLTAGEA=53946,VOLTAGEB=53902,"
   "SHELF-11:SHELF,TEMPERATURE=30C,VOLTAGEA=53890,VOLTAGEB=53879,"
   "SHELF-12:SHELF,TEMPERATURE=25C,VOLTAGEA=53121,VOLTAGEB=53126,"
   "SHELF-13:SHELF,TEMPERATURE=25C,VOLTAGEA=53693,VOLTAGEB=53726,"
   "SHELF-14:SHELF,TEMPERATURE=24C,VOLTAGEA=54093,VOLTAGEB=54072,"
   "SHELF-15:SHELF,TEMPERATURE=22C,VOLTAGEA=53749,VOLTAGEB=53783,"
;

Desired Output



NE name	SHELF	TEMPERATURE	VOLTAGEA	VOLTAGEB
AZID1a	SHELF-1	24C	                  53034	53402
AZID1a	SHELF-2	26C	                  53375	53504
AZID1a	SHELF-2	22C	                  52907	53300
DAND1b	SHELF-1	25C	                  53781	53754
DAND1b	SHELF-2	21C	                  53788	54153
DAND1b	SHELF-3	25C	                  53738	53926
DAND1b	SHELF-4	24C	                  53716	53870
DAND1b	SHELF-5	20C	                  54095	54082
DAND1b	SHELF-6	234C	                  53781	54106




I am very disappointed that you were unwilling to even try to do this on your own. We are not here to act as your unpaid programming staff for constantly changing file formats and requirements. We are here to help you learn how to do stuff like this on your own. There is nothing significantly different about this from your last request, and a simple change to the script I suggested before produces tab separated output similar to what you seem to want, but it doesn't make any attempt to align columns since you explicitly said that you wanted CSV file output (not semi-aligned columns). And, I have no idea where you would get a temperature of 234C when all of the temperatures in your sample input range from 20C through 30C .

With the code:

awk '
BEGIN { OFS="\t"
        print "NE name", "SHELF", "TERMPERATURE", "VOLTAGEA", "VOLTAGEB"
}
/NE name:/ {
        n = $4
}
/:SHELF,/ {
        split($0, t, /[":=,]/)
        print n, t[2], t[5], t[7], t[9]
}' file2

and with file2 containing the input you provided in post #10 in this thread, it produces the output:

NE name	SHELF	TERMPERATURE	VOLTAGEA	VOLTAGEB
AZID1a	SHELF-1	24C	53034	53402
AZID1a	SHELF-2	26C	53375	53504
AZID1a	SHELF-3	22C	52907	53300
DAND1b	SHELF-1	25C	53781	53754
DAND1b	SHELF-2	21C	54188	54153
DAND1b	SHELF-3	25C	53838	53926
DAND1b	SHELF-4	21C	53816	53870
DAND1b	SHELF-5	24C	54095	54082
DAND1b	SHELF-6	20C	54081	54106
DAND1b	SHELF-7	34C	52528	53551
DAND1b	SHELF-8	34C	52129	52597
DAND1b	SHELF-9	29C	53840	53870
DAND1b	SHELF-10	25C	53946	53902
DAND1b	SHELF-11	30C	53890	53879
DAND1b	SHELF-12	25C	53121	53126
DAND1b	SHELF-13	25C	53693	53726
DAND1b	SHELF-14	24C	54093	54072
DAND1b	SHELF-15	22C	53749	53783

Hi Don,

Actually it was mistake from my side there was some issue with TL1 script which was in the bash script and afterwards i added this script to the TL1 expect script and output data was really coming out weird and columns was not getting filled as required now it is fine and got to some more additional fields thanks for your support....