Welcome to the Linux Foundation Forum!

Zeek to CSV bash script help

I am trying to work with a script that was on github - but I am having problems with it. Does anyone see anything wrong with 1) my replacement for FILEPATH and OUTPATH from 2) the template?

1) MY VARIABLE Edits to the template in #2 below

!/bin/bash

bro_in_data=/"path_to_the_input_logs_directory"/ #path to input logs directory
bro_out_csv=/"path_to_the_output_logs_directory"/ #path to output logs directory

echo "Transforming to csv ..."
for log in $(ls $bro_in_data); do

  1. FILEIN=$bro_in_data$log
  2. FILEOUT=$bro_out_csv$log
  3.  
  4. # -d option in zeek-cut convert time values into
  5. # human-readable format. %Y-%m-%dTH%:%M:%S
  6. cat $FILEIN | zeek-cut -c -d > $FILEOUT
  7.  
  8. # If you don´t want to use zeek-cut, comment the line above
  9. # and uncomment the line below
  10. #sed -i '$d' $FILEOUT
  11.  
  12. # Remove line 8
  13. sed -i '8d' $FILEOUT
  14.  
  15. # Remove lines 1 to 6
  16. sed -i '1,6d' $FILEOUT
  17.  
  18. # Delete #fields
  19. sed -i 's/#fields\t//' $FILEOUT
  20.  
  21. # Replace '\t' with ','
  22. sed -i 's/\t/,/g' $FILEOUT

done
echo "Done"

2) TEMPLATE

!/bin/bash

FILEPATH=/"path_to_the_input_logs_directory"/ #path to input logs directory
OUTPATH=/"path_to_the_output_logs_directory"/ #path to output logs directory

echo "Transforming to csv ..."
for log in $(ls $FILEPATH); do

  1. FILEIN=$FILEPATH$log
  2. FILEOUT=$OUTPATH$log
  3.  
  4. # -d option in zeek-cut convert time values into
  5. # human-readable format. %Y-%m-%dTH%:%M:%S
  6. cat $FILEIN | zeek-cut -c -d > $FILEOUT
  7.  
  8. # If you don´t want to use zeek-cut, comment the line above
  9. # and uncomment the line below
  10. #sed -i '$d' $FILEOUT
  11.  
  12. # Remove line 8
  13. sed -i '8d' $FILEOUT
  14.  
  15. # Remove lines 1 to 6
  16. sed -i '1,6d' $FILEOUT
  17.  
  18. # Delete #fields
  19. sed -i 's/#fields\t//' $FILEOUT
  20.  
  21. # Replace '\t' with ','
  22. sed -i 's/\t/,/g' $FILEOUT

done
echo "Done"

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training