- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell Scripting Help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2002 02:43 PM
02-21-2002 02:43 PM
Shell Scripting Help
UID User Name and Information.
In the script I wrote the collumns do not
line up. Can you help me align the collumns?
#!/bin/ksh
cat /etc/passwd > /tmp/build0
sort -t: +2 /tmp/build0 > /tmp/build1
grep -v root /tmp/build1 > /tmp/build2
grep -v datatel /tmp/build2 > /tmp/build3
grep -v wordmarc /tmp/build3 > /tmp/build4
grep -v artsmart /tmp/build4 > /tmp/build5
grep -v udmsmgr /tmp/build5 > /tmp/build6
grep -v :bin: /tmp/build6 > /tmp/build7
grep -v lp /tmp/build7 > /tmp/build8
grep -v uucp /tmp/build8 > /tmp/build9
grep -v www /tmp/build9 > /tmp/build10
grep -v nobody /tmp/build10 > /tmp/build11
grep -v adm /tmp/build11 > /tmp/build12
grep -v sys /tmp/build12 > /tmp/build13
grep -v hpdb /tmp/build13 > /tmp/build14
awk -F: '{print $3, $5}' /tmp/build14 > /tmp/build15
sed 's/,/ /g' /tmp/build15 > /tmp/build16
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2002 02:47 PM
02-21-2002 02:47 PM
Re: Shell Scripting Help
sed 's/,/ /g' /tmp/build15 > /tmp/build16
Should read:
sed 's/,/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2002 02:54 PM
02-21-2002 02:54 PM
Re: Shell Scripting Help
First, I would replace all those temp files with a series of pipes. Simply pipe the output of 1 command to the next. To fix your alignment change your awk print statement to a printf.
e.g.
awk -F: '{printf("%5d\t%s\n",$3,$5)}' /tmp/build14 > /tmp/build15
That should do it, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2002 03:14 PM
02-21-2002 03:14 PM
Re: Shell Scripting Help
If you use the printf to format the output, you shouldn't even need your last sed. I did intentionally insert a tab \t in the printf but, if you prefer, you can simply replace it with a space.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2002 03:18 PM
02-21-2002 03:18 PM
Re: Shell Scripting Help
awk -F: '{print $3,$1,$5}' /etc/passwd | egrep -v 'root|nobody' > /tmp/password_format.out
Add the strings that you would want to get rid of after nobody and as many pipes as you would need ...
Hope this helps !
-Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2002 10:04 PM
02-21-2002 10:04 PM
Re: Shell Scripting Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2002 07:49 AM
02-22-2002 07:49 AM
Re: Shell Scripting Help
# logins -u
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2002 08:06 AM
02-22-2002 08:06 AM
Re: Shell Scripting Help
cat /etc/passwd | sort -t: +2 | grep -v -e root -e datatel -e wordmarc -e artsma
rt -e udmsmgr -e ":bin:" -e lp -e uucp -e www -e nobody -e adm -e sys -e hpdb |
cut -d":" -f3,5 | sed 's/,/ /g'| awk -F: '{printf("%5d %s\n",$1,$2)}'
Note with grep, you can use the "-e" option for more pattern matches.
I also removed all of the unnecessary temporary files, and I used awk to format the output.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2002 08:31 AM
02-22-2002 08:31 AM
Re: Shell Scripting Help
Another thing you may want to consider is using the -f switch in grep. Put all the strings to exclude in a file and use:
cat /etc/passwd | sort -t: +2 | grep -v -f exclude_file | cut -d":" -f3,5 | sed 's/,/ /g'| awk -F: '{printf("%5d %s\n",$1,$2)}'
This might make it easier to maintain should you wish to amend the list.
Rgds, Robin.