LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 08-07-2006, 04:35 AM   #1
narendra.pant
Member
 
Registered: Mar 2006
Posts: 86

Rep: Reputation: 15
Question how to do this


hi fnz

movies pant 8122 jfdjdfhfh
music den 7088 bhfgjhghdhjihfgh

(guys here it is random space or a tab after each word )

i want to cut any field from the above lines
which command i should use.

as i want to get 8122 cut from here n pass it to some other.then in some other case i want to pass den to somwhere else
..
i used the cut command but there i hav to specify the field for each line manually . is there any other option
plz help me out

Last edited by narendra.pant; 08-07-2006 at 04:45 AM.
 
Old 08-07-2006, 04:40 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

You could use grep:

grep -o "8122" infile
or
echo "movies pant 8122 jfdjdfhfh" | grep -o "8122"

Hope this helps.
 
Old 08-07-2006, 05:00 AM   #3
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Sorry, druuna, I think the OP is trying to cut out specific fields, not just get the entire lines. So grep won't help much.

narendra.pant, could you please be a little more specific than "in some cases, I want this" (ie define "some cases").

cut is great for selecting columns out of one or more line. You can select multiple columns (ie the 2nd and 3rd) together as well.
If you need more flexibility than what cut offers, you could take a look at 'awk', but this may be a little hard to learn.

If the space/tab is bothering you, try using 'tr' to replace them.
 
Old 08-07-2006, 05:02 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

@timmeke: That's why grep's -o option is used. It only prints the hit, not the entire line.

So, grep will help
 
Old 08-07-2006, 05:16 AM   #5
narendra.pant
Member
 
Registered: Mar 2006
Posts: 86

Original Poster
Rep: Reputation: 15
mates
i think that grep will not be useful


actually
these are the lines in the 'smbstatus' output
i want to get the pid of the processes which are displayed there n pass it to either kill or nice to reduce the priority of those processes.
simultaneously i want to get the name of the clients .
can yu help it out ..


n how to use 'tr' i dont know .
can yu put an example
actually i m in the lab right now runnin on windows ,
so will try it later . but plz put some example here
thnkx
 
Old 08-07-2006, 05:25 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

To my knowledge the pid in the smbstatus output is always field X, getting this part from the logfile can be done, among others, with awk:

awk '{ print $X }', where X is the number corresponding to the PID field (3 in the above examples). You will end up with this: awk '{ print $3 }' smbstatus.log.

If you want to kill the process automatically (be sure to test this first!):

awk '{ print $3 }' smbstatus.log | xargs kill

Hope this helps.
 
Old 08-07-2006, 05:28 AM   #7
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
@druuna, thanks for the tip on -o. Never used that one before myself.

Try piping smbstatus's output into tr like this:
Code:
smbstatus | tr -s "\t" " "
This will effectively replace one or more tabs by just one space. Can make the 'cut' a little easier, since
you can now just cut on a space delimiter. Simply try adding | cut -d' ' -f2 for the second columne (hosts) or -f3 for the third (IPs).

Another tip: don't use 'nice', use 'renice', since they're already running processes.

However, since you're talking about samba connections, you may want to take a look at the Samba configuration, rather than killing/renicing the processes like this.
 
Old 08-07-2006, 05:58 AM   #8
narendra.pant
Member
 
Registered: Mar 2006
Posts: 86

Original Poster
Rep: Reputation: 15
thanks mates i will try it
got a lot of useful info


thnkx a lot
 
  


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



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

All times are GMT -5. The time now is 06:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration