0

What I want to do is:

>STRIPPER='sed s/admin_editable=\"[01]\"// | sed s/runtime_editable=\"[01]\"//'
>cat file.txt | $STRIPPER > stripped.txt  

i.e. define a shell variable which is a pipeline of multiple commands (mine happen to be sed's), that I can then call later. I'm doing this from the command line now, but may ultimately put it into a script.

I've tried both ' and " for enclosing the command neither works.

sed: can't read |: No such file or directory
sed: can't read sed: No such file or directory
sed: can't read s/admin_editable=\"[01]\"//: No such file or directory
sed: can't read |sed: No such file or directory
sed: can't read s/runtime_editable=\"[01]\"//: No such file or directory
sed: can't read |: No such file or directory

I know that there is probably a single regex that could handle this case, but I'd like to know how to do the pipeline in general.

1
  • Pipelines are part of the shell's grammar, and as such are recognized before any parameter expansion takes place. Commented Feb 5, 2013 at 18:16

1 Answer 1

3

This is a great place to use a function rather than a variable.

stripper() {
    sed s/admin_editable="[01]"// | sed s/runtime_editable="[01]"//
}

cat file.txt | stripper > stripped.txt  

You could also eliminate the useless use of cat:

stripper < file.txt > stripped.txt 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.