I have a shell script that looks for running processes in order to kill them. The script (ksh) gets the PID of these processes using the following:
However, I spotted an issue where PID's of different lengths would cause the logic to fail (since the ps -fu command aligns columns.. therefore there is sometimes a double space between the UID and PID columns (issue a ps -fu $USER to see this)
So, I thought using sed to globally replace the double space with a single would be the way to go....
This returns the PID fine for instances where there is a double or single space between the UID and PID coulmns of the ps -fu command but fails if there are 3 or more spaces. I guess the sed pattern matching doesn't cope with instances like this (where, say 4 spaces should be replaced with a single one).
Any ideas on how to get around this problem using either the above as a starting point, or maybe an alternative approach?
Thanks in advance.
Mike
Last edited by Yogesh Sawant; 05-22-2008 at 12:43 PM..
Reason: added code tags
Making the PID the first field in the output obviating cut, tr, etc. Note that you can specify the order of any field in the full output. In the above case I was only interested in the pid and args to the command, but all the others are available too...
I want to be able to spot double spaces in code and then also replace it with a single space. Double spaces sometimes occur accidentally in code, but most often they are indents or seperate code from comments ("//"). In summary: I want to replace double spaces with single spaces where they do not... (6 Replies)
I have a problem mounting images because of the spaces in the filenames. Does anyone know how to rename files by removing the spaces with the find command?
find Desktop/$dir -name "*.dmg" -print -exec ??? (4 Replies)
Hi everyone
I have a file looks like this
X01 1 JOE 20100312
X02 TOD 20100312
X03 3 SAM 20100312
I wrote a script to assign the values in 5 columns to 5 variables. When I use cut command to assign column 2 or 3, it skips it if it is a space (see below)
... (3 Replies)
Hi
I tried to extract 19 characters (default) enclosed with in tag from a file using cut command. If the characters comprises of double space, the cut command gives the output with a single spacing.
file 1
<name>Kumar Rajasekaran</name>
cut -c7-26 "file1"
the out put i received is ... (48 Replies)
Hello All,
I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out.
My file is like this (<b> means one blank space, <t> means one tab space)-
$ cat file
NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Im running the below commands in a script.
Total_confirms=`cat $OUTPATH/count_po* | head -4 | tail -1`
#
echo "Total Confirms records we need: $Total_confirms" >> $LOG2
The problem is its always returning 4 spaces before the result.. Can I pipe the result into something else to remove the... (5 Replies)
Hey,
I'm using the command from this thread https://www.unix.com/unix-dummies-questions-answers/590-converting-list-into-line.html
to convert vertical lines to horzontal lines. But I need to remove the spaces that is created. Unfortunately I can't figure out where the space is in the code..
I... (2 Replies)
Hi All,
Can the cut command have double character delimiter?
If yes, how can we use it.
if my data file contains :
apple || mango || grapes
i used
cut -f1 -d"||" filename
but got an error.
Plz help....
Thanks. (1 Reply)
i want to give numbers to cut without worrying about the spaces;
echo "12 345 6 78 9" | cut -c 1-9
echo "123 456 789" | cut -c 1-9
echo "1 2 3 4 5 6 7 8 9" | cut -c 1-9
the output of these three must be allways;
123456789
is that posible? (6 Replies)
hey..
i had a problem with the unix command when i want to remove the white spaces in a string..i guess i cud do it with a sed command but i get an error when i give space in the square brackets..
string="nh hjh llk"
p=`echo $string | sed 's/ //g'`
i donno how to give space charater and... (2 Replies)