Bash - make csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash - make csv file
# 1  
Old 07-06-2017
Bash - make csv file

Hello,

im trying to make csv file from a text file that it is the output of pssh command
(multiple ssh )

now if i run the command date on all of our servers:

i get this output :
Code:
[7] 14:02:46 [SUCCESS] 192.168.25.230:22
Thu Jul  6 14:02:46 EEST 2017
192.168.70.230: Thu Jul  6 12:02:46 BST 2017
[8] 14:02:46 [SUCCESS] 192.168.70.230:22
Thu Jul  6 12:02:46 BST 2017
192.168.70.230: Thu Jul  6 12:02:46 BST 2017
[9] 14:02:46 [SUCCESS] 192.168.70.230:22
Thu Jul  6 12:02:46 BST 2017
192.168.11.230: Thu Jul  6 14:02:47 IDT 2017
[10] 14:02:47 [SUCCESS] 192.168.11.230:22
Thu Jul  6 14:02:47 IDT 2017

and i can easly change it to look like that :
Code:
IP,VALUE
192.168.233.75,Thu Jul  6 12:02:46 BST 2017
192.168.233.72,Thu Jul  6 12:02:46 BST 2017
192.168.233.73,Thu Jul  6 12:02:46 BST 2017
192.168.233.74,Thu Jul  6 12:02:46 BST 2017
192.168.233.76,Thu Jul  6 12:02:46 BST 2017
192.168.60.230,Thu Jul  6 13:02:46 CEST 2017
192.168.25.230,Thu Jul  6 14:02:46 EEST 2017


and i get a nice csv-
my issue is when the command output is few rows long.

i have this output :

Code:
[10] 14:06:51 [SUCCESS] 192.168.11.230:22
Name/username              Host                                    Dyn Forcerport ACL Port     Status     
007                        (Unspecified)                            D              A  0        UNKNOWN    
108/108                    (Unspecified)                             D              A  32768    OK (8 ms)  
109                        (Unspecified)                            D              A  0        UNKNOWN    
110                        (Unspecified)                            D              A  0        UNKNOWN

going on and on for all the servers
i need to make the file look like that :

Code:
192.168.11.230, 007  (Unspecified)  D 110  (Unspecified)

and so on so on like a big line for the csv to work

how can i do a command that makes the output 192.168.11.230:22 (specificly all that ends with :22)
be the first in line and all to be one long line (tried xargs but i didnt found a wat to say - do xargs after :22

if i compare a good csv that i made in windows it should look like this :
Code:
IP,VALUE
192.168.233.76:,"007                        (Unspecified)                            D              A  0        UNKNOWN    
108/108                    (Unspecified)                             D              A  32768    OK (8 ms)  
109                        (Unspecified)                            D              A  0        UNKNOWN    
"

thanks

Last edited by batchenr; 07-06-2017 at 08:25 AM..
# 2  
Old 07-06-2017
Try this solution using awk:

Code:
awk -F"[: ]" -v qt=\" '
BEGIN { print "IP,VALUE" }
$7=="22" {
  if(length(IP)) print IP "," qt substr(data,2) qt
  IP=$6
  data=""
  next
}
IP {data=data RS $0 }
END { if(length(IP)) print IP "," qt substr(data,2) qt }
' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash] - Replace blank and string in csv file

Hi all, i have a .csv file with only two columns, like: Login;Status Luca;S Marco; Stefano; Elettra;S Laura; ... I need to replace the blank space on Status column whit Enabled end, on the same column, S whit Disabled, like: Login;Status Luca;Disabled Marco;Enabled Stefano;Enabled... (10 Replies)
Discussion started by: kamose
10 Replies

2. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

3. UNIX for Dummies Questions & Answers

Bash/vi: Make file go away once I close it.

Hi Everyone, It's a little difficult to explain what exactly I am looking for. When I open a file in vi, and then close it, I get back the prompt, but I can still see the file on top. I don't want that. I want to be able to see all the previous commands which I have typed. For example: I... (4 Replies)
Discussion started by: the_learner
4 Replies

4. Shell Programming and Scripting

Bash script help - removing certain rows from .csv file

Hello Everyone, I am trying to find a way to take a .csv file with 7 columns and a ton of rows (over 600,000) and remove the entire row if the cell in forth column is blank. Just to give you a little background on why I am doing this (just in case there is an easier way), I am pulling... (3 Replies)
Discussion started by: MrTuxor
3 Replies

5. Shell Programming and Scripting

Read csv file in bash

how to I use IFS to read 2 files (csv) and run the followiung script ./naviseccli -h 1.2.3.4 storagegroup -addhlu -gname $hostname -hlu $hlu_num -alu $alu_num the csv file for $hostname is host1 host2 . . . for hlu and alu its alu,hlu (2 Replies)
Discussion started by: tdubb123
2 Replies

6. Shell Programming and Scripting

Need help to make a csv file

Hi All :) Need help to create a csv file from some data which is extracted from input file Input file: 1. RUN DATE: 06/02/11 2. SYSTEM: EP0Z 3. PROBLEM TYPE: 0016 -------- ---- ---- 4. JOB NUMBER: 4301 5. JOB NAME:... (4 Replies)
Discussion started by: atul9806
4 Replies

7. Shell Programming and Scripting

how to make my own file as a running log file in bash

Hi, I have written a small script from that iam appending the output to a file.If multiple users invoke the same script or if i invoke the same script n number of times (using &), the output file(ZZ/OUT) contains messup information. #!/bin/bash # echo "Hello" >> /tmp/ZZ/OUT sleep 10 echo... (4 Replies)
Discussion started by: blrguest
4 Replies

8. Shell Programming and Scripting

Edit csv file with bash

I' trying to use bash to edit a csv file from this format: "apples","oranges","grapes" "bread","butter","milk" To this: "apples oranges grapes" So that if I would open the csv file in open office, "apples oranges grapes" Would be in one single cell, and "bread (2 Replies)
Discussion started by: locoroco
2 Replies

9. UNIX for Dummies Questions & Answers

How to make a CSV file from a Raw data

Hi Please help me on this.i have the Following data i want to make it CSV file by a Unix Shell Script. •msgType : 234 ( m_code : 0 # m_name : type # m_data : LOG ) pls help me on this (4 Replies)
Discussion started by: Aditya.Gurgaon
4 Replies

10. Shell Programming and Scripting

Need to modify csv-file with bash script

Hi Guys, I need to write a script, that exports the "moz_places" table of the "places.sqlite"-file (firefox browser history) into a csv-file. That part works. After the export, my csv looks like this: ... 4429;http://www.sqlite.org/sqlite.html;"Command Line Shell For... (11 Replies)
Discussion started by: Sebi0815
11 Replies
Login or Register to Ask a Question