1

I'm working on Unix Build post documentation process, I have a CSV file to be filled in and uploaded for every new build, to ensure the servers are build as per the original request.

The CSV file will have some content already on it, now I have to redirect the Unix command output's to specific row and column into that CSV file. is there a way to achieve that?

Existing CSV file Content: enter image description here

on the above CSV file I have to add the server information which is suppose to be some sort of shell script from column G13.

I've already created script, but that is creating a new CSV and not in particular row or column. not sure how exactly re-direct the command output to respective column and row.

Script:

echo -e "$(cat /etc/redhat-release | cut -d ' ' -f1-5)" >> /tmp/test.csv
echo -e "$(cat /etc/redhat-release | awk '{ print $7 }')" >> /tmp/test.csv
echo -e "$(uname -r)" >> /tmp/test.csv
echo -e "$(dmidecode | grep Product | head -n 1 | cut -d: -f 2)" >> /tmp/test.csv
echo -e "$(grep -c processor /proc/cpuinfo)" >> /tmp/test.csv
echo -e "$(getconf -a | grep PAGES | awk 'BEGIN {total = 1} {if (NR == 1 || NR == 3) total *=$NF} END {print total / 1024" kB"}')" >> /tmp/test.csv
echo -e "$(fdisk -l | grep Disk | grep -i gb | grep -v mapper)" >> /tmp/test.csv
echo -e "" >> /tmp/test.csv
echo -e "$(swapon -s | grep dev | cut -d' ' -f1)" >> /tmp/test.csv
echo -e "$(swapon -s | grep dev  | awk '{ print $3 }')" >> /tmp/test.csv
echo -e "$(hostname -i)" >> /tmp/test.csv
echo -e "$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f4)" >>  /tmp/test.csv
echo -e "$(route -n|grep "UG"|grep -v "UGH"|cut -f 10 -d " ")" >> /tmp/test.csv

I've included the sample csv file which i filled in manually,

enter image description here

any guidance and help will be greatly appreciate.

Edited :

The CSV file is constant and the Values always redirect to same row and column.

  • for hostname row ; hostname for IP address row : /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' for netmask row : /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f4 – user3179298 Jan 25 '16 at 11:39
  • added more details to the question with the script. – user3179298 Jan 28 '16 at 11:28
  • The CSV file always remain same, i guess no need to search the pattern and populate. hostname always at G13. Thanks much for your reply. – user3179298 Jan 29 '16 at 9:16
  • Note that a Windows-style CSV and a Unix-style DSV are not the same. The former is much more complicated to parse due to bad design. – Wildcard Apr 15 '16 at 20:36

Your Answer

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

Browse other questions tagged or ask your own question.