HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk command question
Operating System - HP-UX
1833870
Members
1582
Online
110063
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
08-10-2004 05:31 AM
08-10-2004 05:31 AM
I am creating a file if userid and uid from the passwd file using:
cat /etc/passwd | awk -F":" {print $1 ,$3}
but I also need to insert the hostname into the output, is there a way get this into the awk statement, I already have a variable set for HOST from a command:
HOST=`hostname`
issued earlier in the script.
Thanks
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 05:36 AM
08-10-2004 05:36 AM
Solution
Hi Mike,
You could try using the -v option for awk to set a variable like "HOST" equal to the local hostname and then print the results like this:
cat /etc/passwd | awk -v HOST=`hostname` -F":" '{print HOST, $1 ,$3}'
On my system this returns:
ros87252 root 0
ros87252 daemon 1
ros87252 bin 2
ros87252 sys 3
ros87252 adm 4
ros87252 uucp 5
ros87252 lp 9
ros87252 nuucp 11
...
Regards,
Dave
I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
You could try using the -v option for awk to set a variable like "HOST" equal to the local hostname and then print the results like this:
cat /etc/passwd | awk -v HOST=`hostname` -F":" '{print HOST, $1 ,$3}'
On my system this returns:
ros87252 root 0
ros87252 daemon 1
ros87252 bin 2
ros87252 sys 3
ros87252 adm 4
ros87252 uucp 5
ros87252 lp 9
ros87252 nuucp 11
...
Regards,
Dave
I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 06:43 AM
08-10-2004 06:43 AM
Re: awk command question
another way using awk:
If you have a recent version of awk, such as on 11i, you can do it this way:
awk -F":" '{
print $1, $3, ENIVRON["HOST"];
}'
I'm not sure if HOST needs to be exported from the environment or not.
or you can just do it in the shell
oldIFS="$IFS"
IFS=":"
while read userid x uid stuff
do
print $userid $uid $HOST
done < /etc/passwd
IFS="$oldIFS"
If you have a recent version of awk, such as on 11i, you can do it this way:
awk -F":" '{
print $1, $3, ENIVRON["HOST"];
}'
I'm not sure if HOST needs to be exported from the environment or not.
or you can just do it in the shell
oldIFS="$IFS"
IFS=":"
while read userid x uid stuff
do
print $userid $uid $HOST
done < /etc/passwd
IFS="$oldIFS"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 06:45 AM
08-10-2004 06:45 AM
Re: awk command question
oops that should have been
ENVIRON
and not
ENIVRON
ENVIRON
and not
ENIVRON
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP