Tuesday, January 29, 2013

List classes from faces-config.xml which do not exist using sed

List classes from faces-config.xml which do not exist using sed

 Sed tutorial http://www.grymoire.com/Unix/Sed.html#uh-4
 
[dave@dave tmp]$ more faces-config.xml 
<managed-bean>
        <managed-bean-name>x</managed-bean-name>
        <managed-bean-class>com.dave.x</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
        <managed-bean-name>y</managed-bean-name>
        <managed-bean-class>com.dave.y</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
        <managed-bean-name>z</managed-bean-name>
        <managed-bean-class>com.dave.z</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

List classes
[dave@dave tmp]$  sed -n 's#.*<managed-bean-class>\([\.a-z]*\)</managed-bean-class>#\1#'p faces-config.xml 
com.dave.x
com.dave.y
com.dave.z

Create file names
[dave@dave tmp]$ sed s#\\.#/#g classes.txt 
com/dave/x
com/dave/y
com/dave/z


Change classes file
 sed -i  s#\\.#/#g classes.txt


Add .java
[dave@dave tmp]$ sed   s#\$#.java# classes.txt 
com/dave/x.java
com/dave/y.java
com/dave/z.java



List classes which do not exist
[dave@dave tmp]$ xargs ls < classes.txt 
ls: cannot access com/dave/y.java: No such file or directory
com/dave/x.java  com/dave/z.java


[dave@dave tmp]$ ls -R com/*
com/dave:
x.java  z.java