LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-12-2005, 09:43 PM   #1
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Rep: Reputation: 56
Command line question


Hi folks,

What single command line shall be used to replace 3 separate commands such as;

# lsmod | grep filaA
# lsmod | grep filaB
# lsmod | grep filaB

TIA

B.R.
satimis
 
Old 06-12-2005, 09:54 PM   #2
freegazer
LQ Newbie
 
Registered: Jun 2005
Location: Australia
Distribution: MANDRIVA
Posts: 11

Rep: Reputation: 0
concatenate them using && or ; to run each command sequentially.
the first option may (depending on the context you are using) stop at the first command that returns an erro the second will just keep rolling
 
Old 06-12-2005, 10:08 PM   #3
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Hi freegazer,

Tks for your advice. Test performed as follows;

# lsmod | grep mpu401; grep olp3; grep uart401
Code:
snd_mpu401_uart        10049  1 snd_via82xx
snd_rawmidi            28641  2 snd_seq_virmidi,snd_mpu401_uart
snd                    56741  18 snd_virmidi,snd_seq_virmidi,snd_seq_oss,snd_seq,snd_via82xx,snd_ac97_codec,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_timer,snd_mpu401_uart,snd_rawmidi,snd_seq_device
# lsmod | grep mpu401 && grep olp3 && grep uart401
Code:
snd_mpu401_uart        10049  1 snd_via82xx
snd_rawmidi            28641  2 snd_seq_virmidi,snd_mpu401_uart
snd                    56741  18 snd_virmidi,snd_seq_virmidi,snd_seq_oss,snd_seq,snd_via82xx,snd_ac97_codec,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_timer,snd_mpu401_uart,snd_rawmidi,snd_seq_device
Both hung at the end until I issued
[Ctrl]+ c
to stop them.

It is possible avoiding repeating 'grep'?

TIA

B.R.
satimis
 
Old 06-12-2005, 10:24 PM   #4
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Code:
lsmod | grep -E 'fileA|fileB|fileC'
(the '|' in the grep command is an or, not a pipe).
 
Old 06-12-2005, 10:36 PM   #5
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Hi Berhanie,

Tks for your advice.

Quote:
Code:
lsmod | grep -E 'fileA|fileB|fileC'
(the '|' in the grep command is an or, not a pipe).
It worked but all contents were mixed. Would it be possible to separte the contents indicating their owner?

TIA

B.R.
satimis
 
Old 06-12-2005, 10:49 PM   #6
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
To elaborate on freegazer's suggestion, if you want everything performed sequentially, run somthing like
Code:
lsmod | grep fileA ; lsmod | grep fileB; lsmod | grep fileB
 
Old 06-12-2005, 10:55 PM   #7
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Hi Berhanie,

Tks for your advice.

I'm trying to discover whether it would be possible avoiding repeat-typing 'grep' and 'lsmod'

Your suggestion worked for me but how to separate the printout indicating their ownership

TIA

B.R.
satimis
 
Old 06-13-2005, 09:32 AM   #8
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Quote:
Originally posted by satimis
but how to separate the printout indicating their ownership
Please explain what you mean. I don't understand what you're trying to do.
 
Old 06-13-2005, 10:08 AM   #9
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Hi Berhanie,

# lsmod | grep -E fileA
# lsmod | grep -E fileB
# lsmod | grep -E fileC
each will display one bundle of files

If
# lsmod | grep -E 'fileA|fileB|fileC'
all files will be mix-displayed. It will take time to sort out which of them belongs to fileA, fileB and fileC respectively.

B.R.
satimis
 
Old 06-13-2005, 10:32 AM   #10
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: London, England
Distribution: Ubuntu
Posts: 1,460

Rep: Reputation: 48
What about:

Code:
for name in {filaA,filaB,filaC};do lsmod | grep $name; done
If you need them visisbly split, then you could use:

Code:
for name in {filaA,filaB,filaC};do lsmod | grep $name && echo "-----------"; done
Then you'll get a grep'd lsmod for filaA, followed by a line of dashes, followed by a grep'd filaB, etc

Last edited by oneandoneis2; 06-13-2005 at 10:33 AM.
 
Old 06-13-2005, 11:21 AM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Another way of doing it is to use the '-e' grep option.

lsmod | grep -e pattern1 -e pattern2 -e pattern3

I will sometimes use this with "-v" option to eliminate lines from the locate command which can be very long, using the up arrow to repeat the last line and adding a couple patterns at a time until I eliminate enough results to find what I want.
 
Old 06-20-2005, 09:12 PM   #12
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Hi oneandoneis2,

Tks for your advice.

Quote:
Code:
for name in {filaA,filaB,filaC};do lsmod | grep $name; done
Code:
for name in {filaA,filaB,filaC};do lsmod | grep $name && echo "-----------"; done
Both work for me.

But if one of the files without printout then I have to guess.

B.R.
satimis
 
Old 06-20-2005, 09:28 PM   #13
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Hi jschiwal,

Tks for your advice.

Quote:
lsmod | grep -e pattern1 -e pattern2 -e pattern3
the command is short and easy to remember. However all printout are mixed. Besides it is not easy to find out which file has zero printout.

B.R.
satimis
 
Old 06-20-2005, 09:37 PM   #14
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348
Blog Entries: 1

Rep: Reputation: 37
Quote:
Originally posted by satimis
Hi oneandoneis2,

Tks for your advice.

Both work for me.

But if one of the files without printout then I have to guess.

B.R.
satimis
so try it:
for name in {filaA,filaB,filaC};do lsmod | grep $name && echo "----- $name ------"; done
 
Old 06-20-2005, 09:46 PM   #15
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Hi frandalla,

Quote:
so try it:
for name in {filaA,filaB,filaC};do lsmod | grep $name && echo "----- $name ------"; done
Great. It works for me. Tks

B.R.
satimis
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command line question shadoweyez Linux - Software 2 11-18-2005 06:28 PM
useradd from command line question Strixy Linux - Newbie 4 08-05-2005 06:58 PM
command line question phonecian Linux - Software 2 10-09-2004 08:36 AM
command line / hardware question Drissical Linux - Newbie 3 09-25-2004 10:13 PM
command line question... warheros Linux - Newbie 12 06-25-2003 04:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:35 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