Sunday, July 24, 2016

Shell Script : Reading a file Line by Line in shell script

Reading the file using loop statement

File name : job.txt
File Content :
   Data
   RAM:256 MB
   Bandwidth:1 gbps

Command 1:
        
              while read line
              do
                echo $line
              done <job.txt 
Output :
 
   Data
   RAM:256 MB
   Bandwidth:1 gbps


Command 2:
        
              for line in $(cat job.txt)
              do
                echo $line
              done <job.txt 
Output :
  
   Data
   RAM:256
   MB
   Bandwidth:1
   gbps

No comments:

Post a Comment