LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-08-2017, 10:51 PM   #1
Pzykostyle
LQ Newbie
 
Registered: Oct 2017
Posts: 2

Rep: Reputation: Disabled
How to display the who command output WITHOUT showing the IP address


I'm in an Intro to Linux/UNIX class and I'm having a hard time figuring this one out. I'm being asked to display the students in my class currently logged on but WITHOUT showing the IP address listed at the end of the "who" command.

I've got the initial bit down " who | grep "f132" " but I can't figure that last bit out. I've already tried a few variations of "sed" and "tr" but no luck. Any advice??

ex.

WHAT I GET with " who | grep "f132" ":

f132a12 pts/3 2017-10-08 22:58 (ma.comcast.net)

WHAT I NEED TO SHOW:

f132a12 pts/3 2017-10-08 22:58
 
Old 10-08-2017, 11:30 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,308

Rep: Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744
Well, actually I'd call that a dns address (conventionally IP address means actual digits like 192.168.1.1 )
Anyway, have you considered just using awk (for the whole qn) ?
You could just pipe through 'cut' after your current cmd, but awk can do it all easier.

BTW, when posting code/data/output, please us CODE tags https://www.linuxquestions.org/quest...do=bbcode#code

Last edited by chrism01; 10-09-2017 at 04:17 PM. Reason: typo
 
Old 10-08-2017, 11:34 PM   #3
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
In other words, you want to display only the first 4 columns. Right?

So pass the output of grep (using standard available mechanisms) to a stream editor where you may chop off beyond the fourth column.

ok
 
Old 10-09-2017, 12:16 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,005
Blog Entries: 3

Rep: Reputation: 3633Reputation: 3633Reputation: 3633Reputation: 3633Reputation: 3633Reputation: 3633Reputation: 3633Reputation: 3633Reputation: 3633Reputation: 3633Reputation: 3633
You could do it like this with sed if there is always a parenthesis to identify the component to be removed:

Code:
who | sed -r -n -e '/f123a12/{s/ *\(.*$//;p;}'
Though I am sure there is a more elegant pattern to use.

You could do it with awk, too, but that would change the spacing a little.

Last edited by Turbocapitalist; 10-09-2017 at 12:31 AM.
 
1 members found this post helpful.
Old 10-09-2017, 01:01 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,772

Rep: Reputation: 7058Reputation: 7058Reputation: 7058Reputation: 7058Reputation: 7058Reputation: 7058Reputation: 7058Reputation: 7058Reputation: 7058Reputation: 7058Reputation: 7058
you can use sed to remove (anything):
Code:
sed 's/([^()]*)//'
 
Old 10-09-2017, 01:30 AM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,564

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
Without the -r option a ( is a literal.
A single -e option has no effect (and many -e options are never needed in GNU sed).
Code:
who | sed -n '/f132/{s/ *(.*$//;p;}'
This does a fuzzy match in the whole line including the (hostname) part.

Last edited by MadeInGermany; 10-09-2017 at 01:36 AM. Reason: who cannot do exact match
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passwd command is showing "BAD PASSWORD:" as output but there was nothing after the colon, where there should be some reason output. yogesh95 Linux - Software 4 03-31-2016 07:50 AM
Python showing command output in a frame/label barunparichha Programming 4 08-27-2015 12:18 PM
ifconfig command not showing inet address barsaiyan Linux - Newbie 1 06-04-2012 03:27 PM
Showing command output on the screen while simultaneously logging it. Lufbery Slackware 3 02-04-2010 02:18 PM
Output display address problem in GAS surfer41 Programming 3 10-26-2006 08:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration