Search code examples
shellawksedgrepcut

grep values and re-arranging the file


hi i have a file name test.txt

    (standard input):8:      <property name="ProcedureName" value="abc"/>
(standard input):7:         <property name="PackageName" value="123abc"/>
(standard input):8:         <property name="ProcedureName" value="bac"/>
(standard input):7:      <property name="PackageName" value="bac123"/>
(standard input):8:      <property name="ProcedureName" value="cde"/>
(standard input):7:      <property name="PackageName" value="cd123"/>
(standard input):8:      <property name="ProcedureName" value="b4u"/>
(standard input):7:      <property name="PackageName" value="b4u234"/>

i have to grep only values of packagename and procdeurename from this file in the follwing format: into an o/p file

abc/123abc
bac/bac123
cde/cd123
b4u/b4u234

tried cut and awk but couldnt get that


Solution

  • Try this awk:

    awk -F'"' 'NR%2{p1=$4;next} {print p1 "/" $4}' 
    

    Test:

    $ awk -F'"' 'NR%2{p1=$4;next} {print p1 "/" $4}' file
    abc/123abc
    bac/bac123
    cde/cd123
    b4u/b4u234