Copy data to CSV file from txt output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy data to CSV file from txt output
# 1  
Old 02-07-2016
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?



Code:

> 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
;


Last edited by adgjmpt; 02-07-2016 at 05:50 AM..
# 2  
Old 02-07-2016
Quote:
Originally Posted by adgjmpt
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?



Code:

> 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:
Code:
awk '
/NE name:/ {
	n = $4
}
/:SHELF,/ {
	split($0, t, /[=,]/)
	print n, t[3], t[5], t[7]
}' OFS=, file

producing the output:
Code:
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.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 02-07-2016
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.

Code:
### 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,"

# 4  
Old 02-07-2016
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?
# 5  
Old 02-07-2016
Thanks you very much got it to work but the output is replacing the echo output at the start of the script

Code:
#!/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

# 6  
Old 02-07-2016
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.
# 7  
Old 02-07-2016
Quote:
Originally Posted by adgjmpt
Thanks you very much got it to work but the output is replacing the echo output at the start of the script

Code:
#!/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

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:
Code:
}' OFS=, /cygdrive/c/output/test1/sdh.txt >$i

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

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Python script to run multiple command and append data in output csv file

Experts, I am writing a script and able to write only small piece of code and not able to collect logic to complete this task. In input file have to look for name like like this (BGL_HSR_901_1AG_A_CR9KTR10) before sh iss neors. Record this (BGL_HSR_901_1AG_A_CR9KTR10) in csv file Now have to... (0 Replies)
Discussion started by: as7951
0 Replies

2. Shell Programming and Scripting

Output large volume of data to CSV file

I have a program that output the ownership and permission on each directory and file on the server to a csv file. I am getting error message when I run the program. The program is not outputting to the csv file. Error: the file access permissions do not allow the specified action cannot... (2 Replies)
Discussion started by: dellanicholson
2 Replies

3. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

4. Shell Programming and Scripting

Shell script for .Txt to .csv conversion with data processing

Hi experts, I want to convert a txt file having rows and columns (CNAI_DUMP_raw.txt) by comparing it with another text file (paramaters.txt) and generate a output in CSV which contains only 3rd column from CNAI_DUMP_raw.txt, and the columns mentioned in parameters.txt. FYI: There are two... (16 Replies)
Discussion started by: Gautam Banerjee
16 Replies

5. UNIX for Dummies Questions & Answers

Need help combining txt files w/ multiple lines into csv single cell - also need data merge

:confused:Hello -- i just joined the forums. I am a complete noob -- only about 1 week into learning how to program anything... and starting with linux. I am working in Linux terminal. I have a folder with a bunch of txt files. Each file has several lines of html code. I want to combine... (2 Replies)
Discussion started by: jetsetter
2 Replies

6. Shell Programming and Scripting

Copy Data from CSV file to Excel Sheet using Perl

Hi All, Firstly I will like to wish A Happy New Year to all. Now my issue is I have one csv file say(data.csv) and one excel file say(result.xls) The result.xls contains two sheet name Sheet1 and Sheet2, Now What I am trying to do is to First I want to delete that data of Sheet2 if present any,... (6 Replies)
Discussion started by: adisky123
6 Replies

7. Shell Programming and Scripting

Get Data From CSV File and put into a txt file

Hi Guys, File A I have File A as CSV Format.... No R SS MK Par value S AL A1 PKL123 Lo12 1 S AL A2 PKl123 Lo34 22 S AL A3 PkLK234 Lo67 -34 S AL A4 PkLK235 Lo09 120 S AL A5 PkLK236 Lo76 19 S AL A6 PkLK237 Lo44 -17 S AL A7 PkLK238 Lo90 2 S AL A8 PkLK239 Lo34 -9 I want file B like... (4 Replies)
Discussion started by: asavaliya
4 Replies

8. Shell Programming and Scripting

select data from oracle table and save the output as csv file

Hi I need to execute a select statement in a solaris environment with oracle database. The select statement returns number of rows of data. I need the data to be inserted into a CSV file with proper format. For that we normally use "You have to select all your columns as one big string,... (2 Replies)
Discussion started by: rdhanek
2 Replies

9. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies
Login or Register to Ask a Question