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
# 8  
Old 02-07-2016
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 .

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

# 9  
Old 02-07-2016
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?
This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 02-08-2016
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.

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

Code:


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

# 11  
Old 02-08-2016
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:
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:
Code:
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

# 12  
Old 02-08-2016
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....
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