Operating System - HP-UX
1753854 Members
7994 Online
108808 Solutions
New Discussion юеВ

How to align the space between column in output of the script.

 
SOLVED
Go to solution
Kenan Erdey
Honored Contributor

Re: How to align the space between column in output of the script.

hi,

change givenname as :

givenname=`grep ^"$uname:" /etc/passwd|cut -d: -f5` | sed -e 's/,//g'


Computers have lots of memory but no imagination
Sunny123_1
Esteemed Contributor

Re: How to align the space between column in output of the script.

Hi
try this

givenname=$(echo "${givenname}"|sed -e 's/,/ /g')

Regards
Sunny
Viktor Balogh
Honored Contributor

Re: How to align the space between column in output of the script.

i prefer Hein's solution too, there are a lot of 'heavy' shell commands piped together, and the performance suffers this way. IMHO the best way would be to write it all in awk...

Hein, nice coding! But can we call this
"du -sk * | sort -rn" thing inside of awk? ;)

****
Unix operates with beer.
Suraj K Sankari
Honored Contributor

Re: How to align the space between column in output of the script.

Hi,

>>Here I want the name only but not commas

There are 2 easy way to remove comma
1. open your output into vi
at the vi command prompt give this
:1,$s/,,,//gp

2. assum your output is in out.txt file
now give this command at comman prompt
#sed 's/,,,//'
Suraj
Dennis Handly
Acclaimed Contributor

Re: How to align the space between column in output of the script.

>Viktor: But can we call this "du -sk * | sort -rn" thing inside of awk? ;)

Yes but why bother. ;-)
"du -sk *" | getline
senthil_kumar_2
Regular Advisor

Re: How to align the space between column in output of the script.

Hi Friends,

Thanks a lot now i am getting correct output that i want.

But some entries are repeating, i want to retain only one entry for each. so how to truncat the other entry.

A)My script:

#! /usr/bin/sh

cd /emd/home
printf "%-10s %-15s %-35s %-25s\n" "SPACE" "USERID" "USERNAME" "LINKED_DIRECTORY"
printf "%-10s %-15s %-35s %-25s\n" "-----" "------" "--------" "----------------"
du -sk * | sort -rn | while read space uname
do
#space=`echo $line | awk {'print $1'}`
#uname=`echo $line | awk {'print $2'}`
givenname=`grep ^"$uname:" /etc/passwd|cut -d: -f5|sed 's/,//g'`
linkdir=`ll -nd /emd/home/$uname | awk {'print $11'}`

printf "%-10s %-15s %-35s %-25s\n" "$space" "$uname" "$givenname" "$linkdir"
done


B)Output:


SPACE USERID USERNAME LINKED_DIRECTORY
----- ------ -------- ----------------
7436064 remoquil Soliman Remoquillo
5806320 pzhysl Jason Meyers
3069352 7en0fm Mark Herman
2033224 wabtec Wabtec sharedaccount
2032944 7e8e9u Steven Dettloff
1966224 paez
1888472 mentordata
1810456 infodba Iman Administrator
1650224 tek
1536368 reydl2 Matthew A Sawtell
1443248 redquest
1381032 nzr3k0 Nicholas Shim-Ping
103832 lzrxcl Emma Biddings ---------------------------> First time
Emma Biddings ------------------------------------------------------> second time
6544 oracle Oracle Administrator --------------------> First time
Oracle Administrator -----------------------------------------------> Second time
0 vz1fmk Ish Patel
0 tzrrzp Roopesh Shroff /emd/ansys2/tzrrzp
0 tpw /emd/tpw
0 tombers /emd/ansys1/tombers
0 svihla Gary Svihla /emd/ansys2/svihla
0 stdlib Standards Coord CDMS /users/stdlib
0 schueler /emd/ansys2/schueler
0 rz17by Maximo Test


C)I checked why they are comming two times:


1) 103832 lzrxcl Emma Biddings
Emma Biddings

root@lgapps:/root > grep lzrxcl /etc/passwd

lzrxcl:R1b5gn01B1VGU:1260:1002:Emma Biddings,,,:/emd/ansys2/lzrxcl:/usr/bin/sh
lzrxcl:R1b5gn01B1VGU:1260:1002:Emma Biddings,,,:/emd/ansys2/lzrxcl:/usr/bin/sh


2)6544 oracle Oracle Administrator
Oracle Administrator

root@lgapps:/root > grep ^oracle: /etc/passwd

oracle:oAx6JjE54AHZw:498:1010:Oracle Administrator,,,:/appl/oracle/dba/admin:/usr/bin/sh
oracle:oAx6JjE54AHZw:498:1010:Oracle Administrator,,,:/appl/oracle/dba/admin:/usr/bin/sh


I want only one entry for each directory.

Pls find the attachment for clear details.

Sunny123_1
Esteemed Contributor

Re: How to align the space between column in output of the script.

Hi

Can you attached it once again????


Regards
Sunny
Dennis Handly
Acclaimed Contributor

Re: How to align the space between column in output of the script.

>Pls find the attachment for clear details.

Thanks, that solves the mystery:
givenname=$(grep "^$uname:" /etc/passwd |
awk -F: 'NR == 1 { gsub(",", "", $5); print $5 }')

(Or you could stick a "head -1" in the pipe.)
Sunny123_1
Esteemed Contributor

Re: How to align the space between column in output of the script.

Hi

You can give head option in pipe like

head -1 if you want only one entry.

Regards
Sunny
senthil_kumar_2
Regular Advisor

Re: How to align the space between column in output of the script.

Hi All,

Thanks a lot.

Now everything is fine.