KCITS
asked on
how to export a pipe variable directly to shell command
Hi
I am working on a project to grep/awk/sed a file and directly process a command between two expressions.
for instance if the file reads
XXXXXXXX YYYYY ZZZZZ
firstmatch
du -h /home
secondmatch
AAAAA BBBBBBB CCCC
I can extract the information I need (du -h /home) but can not make it run directly in a shell
sed '1,/firstmatch/d;/secondma tch/,$d |
I just end up with
>
I am working on a project to grep/awk/sed a file and directly process a command between two expressions.
for instance if the file reads
XXXXXXXX YYYYY ZZZZZ
firstmatch
du -h /home
secondmatch
AAAAA BBBBBBB CCCC
I can extract the information I need (du -h /home) but can not make it run directly in a shell
sed '1,/firstmatch/d;/secondma
I just end up with
>
`sed '1,/firstmatch/d;/secondma tch/,$d' file`
ASKER
Hi ozo
Not sure what your suggestion is.
isn't the command 'file' just for determining a file type?
I can export the sed result to a file with
sed '1,/firstmatch/d;/secondma tch/,$d' > /home/testfile.sh
and then run it, but I was hoping to just output and run a single command directly
Not sure what your suggestion is.
isn't the command 'file' just for determining a file type?
I can export the sed result to a file with
sed '1,/firstmatch/d;/secondma
and then run it, but I was hoping to just output and run a single command directly
file was meant to be the name of your file containing
XXXXXXXX YYYYY ZZZZZ
firstmatch
du -h /home
secondmatch
AAAAA BBBBBBB CCCC
you can output to a file with > /home/testfile.sh
but where are you telling sed where to get the input from?
XXXXXXXX YYYYY ZZZZZ
firstmatch
du -h /home
secondmatch
AAAAA BBBBBBB CCCC
you can output to a file with > /home/testfile.sh
but where are you telling sed where to get the input from?
sed '1,/firstmatch/d;/secondma tch/,$d' /path/to/your/file | xargs
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That could be better than `` or $() if there are multiple commands between your expressions
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Guys
sorry my typo in the above expressions I accidentally omitted my source file, it should have read
sed '1,/firstmatch/d;/secondma tch/,$d' /home/testfile.txt|
all accepted solutions worked well, I also experimented and tried the below as an alternative, it worked also.
sed '1,/firstmatch/d;/secondma tch/,$d' /path/to/your/file | sh
cheers
sorry my typo in the above expressions I accidentally omitted my source file, it should have read
sed '1,/firstmatch/d;/secondma
all accepted solutions worked well, I also experimented and tried the below as an alternative, it worked also.
sed '1,/firstmatch/d;/secondma
cheers