Shell script, For loop output to excel as columns

Hi, I have a shell script which analyses the log folder for a specific string and throws me the output. I have used for loop since it does this in multiple servers. Now I want to save the output in a excel in the below format. Can someone please help?

The output which I get

Server1 : count
Server2 : count
.
.
.
Server7 : count

The output format which I want in a excel is
Server1 server2 server3 ...... server7
Count count count ...... count

I want this output as columns in excel

Please post your shell script if you need help.

Thanks.

Hi,

This is the second time that this has been posted, please contact a moderator if you think that you have posted on the wrong forum. You should also post your code, it will allow people to deliver more targeted help to you.

Regards
Gull04

Hi, this is my code

TimeStamp=$(/bin/date "+%Y-%m-%d")

for num in $(seq 10 16) 19; do
echo -n "server${num}: "
grep -n 'Execution Complete ' App_log_${TimeStamp}_server${num}* | wc -l
Done > output/path/file.txt

Try the following

#!/bin/sh
TimeStamp=$(/bin/date "+%Y-%m-%d")
servernums="$(seq 10 16) 19"

# print args on one line separated by ","
myprint(){
  [ $# -ge 1 ] || return
  printf "%s" "$1"
  shift
  [ $# -ge 1 ] &&
    printf ",%s" "$@"
  printf "\n"
} 

# line one
myprint $(
for num in $servernums; do
  echo "server${num}"
done
)

# line two
myprint $(
for num in $servernums; do
  grep -c 'Execution Complete ' App_log_${TimeStamp}_server${num}*
done
)

Save the output as .csv, then Excel should be able to open it.

Try also

FN="App_log_$(/bin/date "+%Y-%m-%d")_server"
TMP="Execution Complete "
for num in $servernums
  do  A="$A server${num}"
      B="$B $(grep "$TMP" $FN$num|wc -l)"
  done
echo $A
echo $B

Great ! Both the code worked. Thankyou so much. Can you also help me with the code to append the output the as a row to the excel everytime when this script gets executed ?

Any attempt / idea / thought from your side on this? How should the final result look like?

The cvs file will look like

Date         server10   server 11   server12   server13 
Today date    57         124                234          67

So, whenever I run the script the second row i.e., the counts row alone should get appended and everyday a new second row should get appended in the below cells. The output I am expecting should look like

Date         server10   server 11   server12   server13 
Today date    57         124                234          67
Tomorrow     347        5667             67             566
Next day        345         234              453           69

Hmmm - try

HD="Date"
DT="$(/bin/date "+%Y-%m-%d")"
ON="output/path/file.txt"
FN="App_log_${DT}_server"
TMP="Execution Complete "
for num in $servernums
  do  HD="$HD server${num}"
      DT="$DT $(grep "$TMP" $FN$num|wc -l)"
  done
[ ! -f "$ON" ] && echo $A $HD > "$ON"
echo $DT >> "$ON"

It works. Thanks again!

Hi, I need a help again I wanted to add one more column as TOTAL and I want the sum of all the values in the row to the value of column

server10   server 11   server12     Total
 57         124                234            sum(c1-c3)
 347        5667             67              sum (c1-c3)
 345         234              453               sum(C1-C3)

Here the value of total should be the sum of each values in the row

Again: Any attempt / idea / thought from your side?

I am not sure about it

HD="Date"
DT="$(/bin/date "+%Y-%m-%d")"
ON="output/path/file.txt"
FN="App_log_$DT_server"
TMP="Execution Complete "
for num in $servernums
  do  HD="$HD server${num}"
      DT="$DT $(grep "$TMP" $FN$num|wc -l)"
  done
[ ! -f "$ON" ] && echo $A > "$ON"
echo $DT >> "$ON"

May be we can create a new variable so that it holds the value of the sum of server${num}

Hmmm - I don't see too much of your own in your post; you even copied the incorrect $A output that I now corrected in my original post #10.
Howsoever, try

HD="Date"
DT="$(/bin/date "+%Y-%m-%d")"
FN="App_log_${DT}_server"
ON="output/path/file.txt"
SRC="Execution Complete "
for num in $servernums
  do    HD="$HD server${num}"
        TMP=$(grep "$SRC" $FN$num|wc -l)
        DT="$DT $TMP"
        (( TOT += TMP ))
  done
[ ! -f "$ON" ] && echo $HD Total > "$ON"
echo $DT $TOT >> "$ON"
Moderator comments were removed during original forum migration.