Suppose there is a file named file1.txt which contains
----
Hello World
This is a simple command
------
Now the command will be like this
$cat file1.txt | while read line; do; echo $line | tr "a-z" "A-Z"; done
Now what happens here
first cat prints the content of the file which instead of going to stdout goes as input to the next
command through the PIPE ( | ). Here we runs a loop which reads one line at a time it gets as
input from file1.txt, and again PIPED to another command tr which is a translation command
converting each character from small case ("a-z") to upper ("A-Z"). while loop runs until last line
of the file is reached.
Output is
----
hELLO wORLD
tHIS IS A SIMPLE COMMAND
------
----
Hello World
This is a simple command
------
Now the command will be like this
$cat file1.txt | while read line; do; echo $line | tr "a-z" "A-Z"; done
Now what happens here
first cat prints the content of the file which instead of going to stdout goes as input to the next
command through the PIPE ( | ). Here we runs a loop which reads one line at a time it gets as
input from file1.txt, and again PIPED to another command tr which is a translation command
converting each character from small case ("a-z") to upper ("A-Z"). while loop runs until last line
of the file is reached.
Output is
----
hELLO wORLD
tHIS IS A SIMPLE COMMAND
------
No comments:
Post a Comment