Wednesday, 5 March 2014

Parsing of text file throgh Shell script

Sample text file

Name,CompanyName,Id,#status,Project,#flag
ABC,Google,1,#Success,website,#10flag
XYZ,Microsoft,2,#Success,FrameWork,#12flag
QQQ,Ccc,#FAILED,RAW,#00flag

save file as SampleText.txt

1.View the file on the console/output screen by
  
             cat SampleText.txt

2.search lines having Success  Keyword

            cat SampleText.txt | grep 'Succes'

3.First column separated by ,

            cat SampleText.txt | grep 'Succes' | awk -F, '{print $1}'
o/p
ABC
XYZ


Here,comma separated values represents the column .

4. Second column separated by ,
          cat SampleText.txt|grep 'Succes' |awk -F, '{print $2}'
o/p
Google
Microsoft


5.Whole line 

        cat SampleText.txt|grep 'Succes' |awk -F, '{print $0}'
o/p
ABC,Google,1,#Success,website,#10flag
XYZ,Microsoft,2,#Success,FrameWork,#12flag

6. First Column separated by #
           cat SampleText.txt|grep 'Succes' |awk -F# '{print $1}'

o/p   

ABC,Google,1,
XYZ,Microsoft,2,


7.Third Column separated by #
           cat SampleText.txt|grep 'Succes' |awk -F# '{print $3}'
o/p 

10flag
12flag




No comments:

Post a Comment

Cool Blue Outer Glow Pointer