Search code examples
shelltestingautomationbehat

How to save result in separate column in excel from shell script?


I am saving the executed result in one of the excel sheet. The result will show in new rows like below:

enter image description here

I have used the below command :

$ bash eg.sh Behatscripts.txt | egrep -w 'Executing the|scenario' >> output.xls

I want to display result like below:

|                  A                   |          B           |       c     |
1 Executing the script:cap_dutch_home    1 scenario(1passed)
2 Executing the script:cap_english_home  1 scenario(1passed)

One more thing is while executing it will create output.xls separate file, instead of using already existed. Thanks for any suggestions.


Solution

  • You can use this;

    with awk;

    bash eg.sh Behatscripts.txt | egrep -w 'Executing the|scenario' | awk 'BEGIN {print "Column_A\tColumn_B"}NR%2{printf "%s \t",$0;next;}1' output.xls
    

    without egrep

    bash eg.sh Behatscripts.txt | awk '/Executing the|scenario/' | awk 'BEGIN {print "Column_A\tColumn_B"}NR%2{printf "%s \t",$0;next;}1' >> output.xls