Thursday, March 5, 2015

script for reading file or stream

I often wanted to pass the file to a pipeline some command, and also if the file is parameter to command it should accept


Voila!!

here is 'stream.sh'

#!/bin/bash

file=${1:--}

cat $file 


Usage and output

$ ./stream.sh underSTANDING.txt 

If you understand, say "understand".
If you don't understand, say "don't understand".
But if you understand and say "don't understand".
How do I understand that you understand? Understand!



$ cat underSTANDING.txt | ./stream.sh 

If you understand, say "understand".
If you don't understand, say "don't understand".
But if you understand and say "don't understand".
How do I understand that you understand? Understand!



$ ./stream.sh < underSTANDING.txt 

If you understand, say "understand".
If you don't understand, say "don't understand".
But if you understand and say "don't understand".
How do I understand that you understand? Understand!

No comments:

Post a Comment