I have written a script which displays Name and department of the user and that works.Moreover i am trying to draw a divider line with Name title assign to the columns as they needed. I am trying to do it with printf but somehow not able to get it as of now.. any help will be appreciated..
below is the script and expected result..
#!/bin/sh
for names in `cat namefile`;
do
DATA1="`/grid/common/bin/cod -u $names | awk -F: '/Department/ {print $2}'`"
DATA2="`/grid/common/bin/cod -u $names | awk -F: '/Name/ {print $2}'`"
#printf '%*s\n' "${COLUMN'S:-$(tput cols)}" '' | tr ' ' -
printf "%-50s : %10s\n" "$DATA2" "$DATA1"
done
bash-4.1$ sh Userdetail.sh
Karn Kumar : TT, Infra, VM & India
Manas . : TT, Infra, VM & India
Pranjal Agrawal : TT, Infra, VM & India
Rogen Mana : PP OPS-Brazil
I'm trying to find a way draw a line with Titles before the output will display like below expected:
Name Department
--------------------------------------------------
Karn Kumar : TT, Infra, VM & India
Manas . : TT, Infra, VM & India
Pranjal Agrawal : TT, Infra, VM & India
Rogen Mana : PP OPS-Brazil
Just for more how to know on the command part..
bash-4.1$ /grid/common/bin/cod -u karn
Name: Karn Kumar
Title: IT -Staff Systems Engineer
Department: TT, Infra, VM & India
Mgr: KK LIN
Mgr Login: ttlin
E-Mail: karn@abc.com
Phone: 09999999999
Internal #:
Ext: 4848
Cell: 8777880559
Fax: -
Building: NOIDA 03
Floor: 03
Room: 3.3.109
$( command )
instead. It makes it much easier to read and avoids certain problems. In addition , don't usefor variable in $(cat file.txt)
. There are other, better ways to read a file line-by-line. See http://mywiki.wooledge.org/BashFAQ/001 – Sergiy Kolodyazhnyy Jan 19 '17 at 04:03