Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm executing a Linux command and executing from an automated script.

ps | awk '/dspload -d 1 -e/&&!/awk/{print $1}'

Now when I see the logs of the script and look at the location where it gets executed I see something like this

root@dm365-evm:/usr/share/ti/dvtb# ps | awk '/dspload -d 1 -e/&&!/awk/{print $1}'

That causes command not to run properly.

Could anyone suggest how I can run it like:

root@dm365-evm:/usr/share/ti/dvtb# ps | awk '/dspload -d 1 -e/&&!/awk/{print $1}'
share|improve this question

migrated from stackoverflow.com Jan 24 '11 at 14:16

This question came from our site for professional and enthusiast programmers.

closed as not a real question by sleske, Nifle, Sathya, Diago Jan 26 '11 at 15:50

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

What does "not to run properly" mean? The expected output is not clear from this description of the problem. –  Johnsyweb Jan 24 '11 at 6:44
Johnsyweb from automated script command is running like this –  AMIT Jan 24 '11 at 6:47
$1}' is getting into next line an di don't want it to go in new line –  AMIT Jan 24 '11 at 6:49
is this question deserve to be got negtive vote...i don't like it –  AMIT Jan 24 '11 at 10:12
Please explain what output you get from the command, and what output you would like to get. Like this the question is pointless. Voting to close. –  sleske Jan 24 '11 at 16:29

3 Answers 3

Given the comments after the question, are you sure the text editor you are using to write the script isn't adding newlines (word wrapping) into your command? I.e., does your script file contain a newline within the argument to awk?

share|improve this answer
no i am sure text editor is not adding new line –  AMIT Jan 24 '11 at 6:53
one of the possiblty i would imagine is command doesn't have enough time to be written on prompt –  AMIT Jan 24 '11 at 6:55
@AMIT: How do you know that the command is being split into two lines? How are you running it in your script? –  Jeremiah Willcock Jan 24 '11 at 6:56
In logs i can command gets splited and this how am running script –  AMIT Jan 24 '11 at 6:59
cmd = "ps | awk '/#{process}/ && !/awk/ {print $1}'" output = board.send_puts(cmd, @target_prompt) where @target_prompt is :/usr/share/ti/dvtb –  AMIT Jan 24 '11 at 6:59

You might have to escape the dollar sign, e.g. \$1.

share|improve this answer
thanks jk for ur response u want to say i should run this command like ps | awk '/dspload -d 1 -e/&&!/awk/{print \$1}' –  AMIT Jan 24 '11 at 6:45
yes, try that and see if it works –  jk Jan 24 '11 at 6:47

I'm not sure why this has been migrated from StackOverflow, as the question is as unclear here as it is there.

It looks like you are trying to get a list of PIDs of all running processes matching "dspload -d 1 -e" but excluding awk (which you are using to filter the output of ps and just grab the first column.

It also looks like your command, ps | awk '/dspload -d 1 -e/&&!/awk/{print $1}' is working from the command-line. On whichever operating system you are running, within whichever shell you are running. I suspect that the output looks something like:


I gather that rather than try to remember this complicated command-line, you have put it into some kind of file and are trying to run it as a shell-script but this is not working. I have no idea what this shell script looks like.

I can tell you that if your shell script looks like this:

ps | awk '/dspload -d 1 -e/&&!/awk/{print $1}'

Then running it will give you the same output as running the command at a bash prompt on Mac OS X.

If you have you have extracted the process to a variable, you'll need to ensure that this is is expanded within the call to awk, viz:

process="dspload -d 1 -e"
ps | awk '/'${process}'/&&!/awk/{print $1}'

Using single quotes (') will mean that $1, which has a special meaning within the Bourne Shell, will not be expanded (but will be interpreted by awk.

Any decent editor will highlight the syntax for you and help you to spot any errors.

share|improve this answer
thanks Johnsweb for ur wonderfull response ... my question is quite simple when i tried to run this commnad ps | awk '/dspload -d 1 -e/&&!/awk/{print $1}' on prompt what i see is > sign even if tried to run ps | awk '/top -b -d 1/ && !/awk/ {print $1} got same thing ..i don't why people not able to get it ..... –  AMIT Jan 31 '11 at 5:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.