I want to put a lot of filtering in a Bash script, to get my filtering commands a little shorter:
#before:
$ cat unreadable.log | grep "bla" |[...]| sed "s/blubb//" >>readable.log
#after:
$ cat unreadable.log | the_script_I_m_writing.sh >>readable.log
But how to handle the IO in the bash-script correctly, that the after line can be executed as shown?
As you can see inside the bash-script there will be a lot of simple commands that are piped together. All this piping should just begin with stdin and send the final result out to stdout.
catreads from standard input if no file argument is given.Alternatively, just write a script that accepts the source file name as argument.
Use:
./script unreadable.log.In this simple case, you can also skip the
cat, and just start withgrep.Use: