0

i have a problem. I want to make a bash script that writes data to new column every time i run script. For example every week i check how many files in each folder i have.

find /home/user/admin/stuff/ -mtime -7 | wc -l >> results.xls find /home/user/admin/old/ -mtime -7 | wc -l >> results.xls 

I run script every Monday, but i don't want to overwrite data. I need that new data will be in new column.

For example:

Week1 Week2 Week3 ... 2 3 5 1 2 3 
1
  • im sorry in a new column :)) Commented Oct 27, 2016 at 9:58

2 Answers 2

0
#!/bin/bash output_file=/tmp/results.xls [ ! -f ${output_file} ] && echo -e "\n\n\n" > ${output_file} stuff_count=$(find /home/user/admin/stuff/ -mtime -7 | wc -l) old_count=$(find /home/user/admin/old/ -mtime -7 | wc -l) now=$(date +%y%m%d) sed -i "1 s/$/\t$now/" /tmp/out.txt sed -i "2 s/$/\t$stuff_count/" /tmp/out.txt sed -i "3 s/$/\t$old_count/" /tmp/out.txt 
1
  • Sed is somehow hard to use when it would come to combine more lines. I would suggest paste. Something like paste results.xls <(date +%y%m%d; find /home/user/admin/stuff/ -mtime -7 | wc -l; find /home/user/admin/old/ -mtime -7 | wc -l) > /tmp/tempresults; mv /tmp/tempresults results.xls. Of course, in case of more complicated output, it could be prepared in some temporary file and then merged with paste file_a file_b. Commented Oct 27, 2016 at 11:36
0

You can have a the output in this way.

week="" week=`date` echo $week >> results.xls find /home/user/admin/old/ -mtime -7 | wc -l >> results.xls # cat results.xls Thu Oct 27 14:16:29 IST 2016 0 2 

This is just an example. You can modify it in your way.

1
  • i'm sorry i mean in a new column Commented Oct 27, 2016 at 10:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.