- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: A "for" question
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
Discussions
Discussions
Forums
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
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
тАО10-08-2004 12:39 AM
тАО10-08-2004 12:39 AM
How I can proccess on the fly (without write a temp file) line-by-line and not space-by-space something like this into a "for" cycle:
SESSIONS=`who -u|sort`
for SESION in $SESSIONS
.
.
.
done
Rgds.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2004 12:49 AM
тАО10-08-2004 12:49 AM
Re: A "for" question
for SESION in `who -u |sort`
will give you the whole line, one by one.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2004 12:50 AM
тАО10-08-2004 12:50 AM
Re: A "for" question
OIFS=$IFS
IFS="
"
for SESSION in `who -u | sort`
do
echo $SESSION
done
IFS=$OIFS
this will print one entire line per itteration of the for loop.
You can split this out into separate variables eg with
OIFS=$IFS
IFS="
"
for SESSION in `who -u | sort`
do
IFS=$OIFS
set $SESSION
echo "user: $1, client: $8"
done
Note the restting of IFS to the saved OIFS _within_ the loop, so that "set" uses the whitespace rather than carriage return as field separator.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2004 12:50 AM
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2004 12:53 AM
тАО10-08-2004 12:53 AM
Re: A "for" question
This should also work:
# who -u | sort | xargs
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2004 01:01 AM
тАО10-08-2004 01:01 AM
Re: A "for" question
for i in $(who -u | sort | awk '{print $1}')
do
.
.
.
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2004 01:07 AM
тАО10-08-2004 01:07 AM
Re: A "for" question
for SESSION in `who -u|sort`
do
echo $SESSION
done
The output is:
user1
pts/tc
Oct
8
13:46
0:15
18272
12.4.49.29
user2
pts/tDb
Oct
8
07:19
0:14
29454
12.4.49.24
And I need this instead:
user1 pts/tc Oct 8 13:46 0:15 18272 12.4.49.29
user2 pts/tDb Oct 8 07:19 0:14 29454 12.4.49.24
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2004 01:12 AM
тАО10-08-2004 01:12 AM
Re: A "for" question
who -u | sort > /tmp/file
while read session
do
echo ${session}
done < /tmp/file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2004 01:16 AM
тАО10-08-2004 01:16 AM