LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sed substitute for my username? (https://www.linuxquestions.org/questions/linux-newbie-8/sed-substitute-for-my-username-439998/)

camaroblue87 04-29-2006 09:32 AM

Sed substitute for my username?
 
Hi everyone, i have been stuck on a problem that i cant seem to find an answer for, i tried many things that didnt work.

the problem is:
[ list all your processes, using sed to substitute "me" for your username.]

So i am asuming that after i get the right sed command i will be able to do something like [ ps -u me ]

this is what i have tried so far and they have not worked

Code:

sed 's/s06-cs271-s09/me/g' </home/s06-cs271-s09 >/home/s06-cs271-s09.new

sed 's/s06-cs271-s09/"me"/g' sedtest.txt

any help would be greatly appreciated, thanks

burninGpi 04-29-2006 11:07 AM

try this:
Code:

ps -ux | sed "s/\$$USER/me/"
the \$ guards the RE so if your username is in the command, it doesn't get substituted also. using $USER makes the script shorter, and the "g" flag is unneeded. Put this script in your path (eg ~/bin/pssub):
Code:

#!/usr/bin/sed -f
s/$USER/me/

chmod 755, and you can run it with
Code:

ps -ux | pssub


All times are GMT -5. The time now is 12:29 AM.