linux - Parsing a file which is separated by "categories" -
here issue:
a) i'm scripting newbie
b) have file need data separated csv style table, problem there 3 areas of data (see below):
(area 1, not relevant) total ipv4 packets captured: 2245686 # l4 protocol # packets relative frequency[%] protocol description 1 5602 0.249456 internet control message protocol .... (more data here) (area 2, relevant) total tcp packets: 2238186 # port # packets relative frequency[%] protocol description 22 2138555 95.548583 secure shell (ssh) protocol .... (more data here) (area 3, relevant) total udp packets: 1623 # port # packets relative frequency[%] protocol description .... (more data here) (area 4, relevant) total scp packets: 0 # port # packets relative frequency[%] protocol description .... (more data here)
(this tranalyzer _protocols output)
so need make output like:
# port,# packets,relative frequency[%],protocol description 22,2138555,95.548583,the secure shell (ssh) protocol,(more data...)
but need take data each area , put in separate csv file (tcp, udp, scp) flows put in table (each in different _protocols file in different subdirectories) data can go 1 of these 3 files , build memory-crushing spreadsheet (hence why csv.)
i'm open other way represent can suggest.
much appreciated!
following command extract , convert data file csv.
change x
tcp, udp or scp extract particular set of data.
change <analyzer_output.txt>
proper file name before executing.
x="scp"; \ cat <analyzer_output.txt> | sed "1,/^total $x/d; /^total /,\$d; /^\s*$/d" | \ sed 's/\([0-9]\)\s\+\([0-9]\)/\1,\2/g; s/\([0-9]\)\s\+\([a-za-z]\)/\1,\2/g' \ > $x.csv
resulting scp.csv file below sample data
41,2138555,95.548583,the secure shell (ssh) protocol 42,2138555,95.548583,the secure shell (ssh) protocol
sample data file
total ipv4 packets captured: 2245686 1 5602 0.249456 internet control message protocol 2 5602 0.249456 internet control message protocol total tcp packets: 2238186 21 2138555 95.548583 secure shell (ssh) protocol 22 2138555 95.548583 secure shell (ssh) protocol total udp packets: 1623 31 2138555 95.548583 secure shell (ssh) protocol 32 2138555 95.548583 secure shell (ssh) protocol total scp packets: 0 41 2138555 95.548583 secure shell (ssh) protocol 42 2138555 95.548583 secure shell (ssh) protocol
Comments
Post a Comment