Linux Today: Linux News On Internet Time.
Search Linux Today
Linux News Sections:  Developer -  High Performance -  Infrastructure -  IT Management -  Security -  Storage -
Linux Today Navigation
LT Home
Contribute
Contribute
Link to Us
Linux Jobs


Top White Papers

More on LinuxToday


Bash Tricks II: Repetitive tasks on files

Jun 07, 2009, 14:02 (0 Talkback[s])
(Other stories by Edmundo Carmona)

[ Thanks to Edmundo for this link. ]

"Second we have the while read variable; do x; y; z; done. This construct allows us to read from the standard output line by line placing the content of each line in a variable (multiple variables can be used, in that case a single word from the standard input will be placed in each variable). In our case, we used $filename as our variable (be careful not to use $ on the while read).

"Then the ``s. These kids allow us to run a command so that its output can be assigned. In our case, we are listing the files of a tgz file, grepping to find the pattern of the file we are looking for and then counting the lines that come out of grep. The number of lines is what is saved in the variable $lines."

Complete Story

Related Stories: