Repeatedly getting command substitution: line 3: syntax error near unexpected token
Hello mates
I am repeatedly getting error: command substitution: line 3: syntax error near unexpected token `(' command substitution: line 3: `ps -eo pmem,args | sort -k 1 -r | head -2 | sed '1d' | tee > ( awk {print'$2'}> new.txt) | cut -d'.' -f1' I need to pass the value of `ps -eo pmem,args | sort -k 1 -r | head -2 | sed '1d' | tee > ( awk {print'$2'}> new.txt) | cut -d'.' -f1' to a variable mem. I am using #!/bin/bash This command works on shell without any issue. Help required..... |
There is just a dollar missing before the opening-parenthesis.
Yves. |
Hello boss,
cpu.sh: line 4: $(awk {print'$2'} > new.txt): ambiguous redirect |
Hi,
I cannot get your posted command to work at all. After A litle re-write I came up with this: ps -eo pmem,args | sort -k 1 | sed '$d' | tail -1 | awk '{ pint $2 > "new.txt" } { printf("%.0f\n", $1) }' This looks for the process that takes the most memory. The name is put in a file (new.txt) and the number is outputted to screen (all behind the . is removed). I hope this does what you want. |
But this command is not writing the output to new.txt.
ps -eo pmem,args | sort -k 1 | sed '$d' | tail -1 | awk '{ pint $2 > "new.txt" } { printf("%.0f\n", $1) }' I need to the get the service taking memory write to a file and the mem usage to variable. Thanks for your effort |
Hi,
It does on my side: Code:
$ cat new.txt |
Thanks for your valuable time.It worked.
|
When I executed the posted command in a bash terminal I got the same error message which you get when running the bash script.
The command started working when the space between '>' and '(' was removed. |
Quote:
Please put the SOLVED tag on this thread (First post: Thread Tools pull down menu. Option is among them). |
All times are GMT -5. The time now is 06:03 AM. |