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 |
Hi,
You could use grep: grep -o "8122" infile or echo "movies pant 8122 jfdjdfhfh" | grep -o "8122" Hope this helps. |
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. |
Hi,
@timmeke: That's why grep's -o option is used. It only prints the hit, not the entire line. So, grep will help ;) |
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 |
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. |
@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" " " 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. |
thanks mates i will try it
got a lot of useful info thnkx a lot |
All times are GMT -5. The time now is 05:42 PM. |