Hey everyone,
So newbie when it comes to scripting and lurked on these pages for some time as I slowly learn. I'd like to thank everyone for taking the time to share their knowledge, and would like to think I've picked up a something from these forums.
What I'm trying to do, is create a csv from four disparate files containing data.
Here's my current script. Its meant to have multiple files from multiple hosts, hence the loop.
I am limited to the tool set on AIX, and cannot use any GNU tools.
#!/bin/ksh
set -A allHosts $(ls -1 *.out | awk -F\. '{print $1}' | sort -u | uniq)
echo "host,accounts,max,pwd,standard"
for h in ${allHosts[@]}; do
col1=$(cat ./${h}.account.out)
col2=$(cat ./${h}.max.out)
col3=$(cat ./${h}.pwd.out)
col4=$(cat ./${h}.standard.out | sed -e 's/^[ \t]*//')
echo "${h}","${col1}","${col2}","${col3}","${col4}"
unset col1
unset names
unset col2
unset col3
unset col4
done
File are setup like:
host1.max.out
9
host1.account.out
root
user1
user2
host1.pwd.out
abc pwd=
host1.standard.out
standard:
user = true
expires = 0
core_path = on
default_roles =
Results I'm current receiving:
host,accounts,max,pwd,standard
host1,root
user1
user2,9,abc pwd=,standard:
user = true
expires = 0
core_path = on
default_roles =
Desired output:
host,account,max,pwd,standard
host1,root,9,abc pwd=,standard:
,user1,,,user = true
,user2,,,expires = 0
,,,,core_path = on
,,,,default_roles =
Thank you for your time and my apologies if this has been asked before, but my searching abilities has failed me.