0

I have a Unix shell script which generates output from a log.

for i in HistSimBasislieferung hedgeAccountingF4PublicSend;do
  report1=$(echo -n $i:)
  date1=$(grep -e $i $PALME_CONF | grep "The job finished" | tail -1 | awk '{print $1,$2}'|\<br/> sed 's/^.\(.*\).$/\1/')
  final="$report1 $date1"
  echo "$final"
done

At the moment the output looks like this:

HistSimBasislieferung 2015-03-11 01:03:02
hedgeAccountingF4PublicSend 2015-03-11 00:16:34

But what I want is something like this:

HistSimBasislieferung,hedgeAccountingF4PublicSend
2015-03-11 01:03:02,2015-03-11 00:16:34

Do you have any suggestions on how this could be done?


I did it the way you suggested:

   for i in HistSimBasislieferung hedgeAccountingF4PublicSend;do
           echo -n $i > report_log
           grep -e $i $PALME_CONF | grep "The job finished" | tail -1 | awk '{print $1,$2}' | sed 's/^.\(.*\).$/\1/' > date_log

   done
   cat < report_log | xargs echo | tr ' ' ',';
   cat < date_log | xargs echo | tr ' ' ',';
   echo "" > report_log; echo "" > date_log

but the output gave:

hedgeAccountingF4PublicSend2015-03-11,00:16:34    
I need it like this:  
HistSimBasislieferung,hedgeAccountingF4PublicSend,  
2015-03-11 03:05:40,2015-03-11 02:12:19,
0

This one liner might look ugly but I think it does the job (if I understand your use case correctly).

your_shell_script.sh  | cut -d ' ' -f 1 | tr '\n' ',' | sed 's/,$/\n/'; your_shell_script.sh | cut -d ' ' -f '2-' | tr '\n' ',' | sed 's/,$/\n/'  
0

It is a loop script, so it will overwrite the variable every loop. My suggestion here, is to create logfile for the "report" and a logfile for "date" too (append log).

At the end of your script (right below the "done" line), execute the command below:

cat <\report_log_file> | xargs echo | tr ' ' ',';
cat <\date_log_file> | xargs echo | | tr ' ' ','

or create another loop script.

for i in <\report_log_file> <\date_log_file>; do
   cat $i | xargs echo | tr ' ' ',';
done

then, clear the logfiles:

echo "" > report_log_file; echo "" > date_log_file
  • Hi David for i in HistSimBasislieferung hedgeAccountingF4PublicSend;do echo -n $i > report_log grep -e $i $PALME_CONF | grep "The job finished" | tail -1 | awk '{print $1,$2}' | sed 's/^.(.*).$/\1/' > date_log done cat < report_log | xargs echo | tr ' ' ','; cat < date_log | xargs echo | tr ' ' ','; echo "" > report_log; echo "" > date_log gives hedgeAccountingF4PublicSend2015-03-11,00:16:34 – Uensal Mar 11 '15 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.