Search code examples
shellunixhp-ux

Get a portion of a line from a file in unix


I have a file named , temp.lst whose contents are something like this :

1,13d0
< /hello/ux/PH/src/DEMO/dir/web/HelloWorld.java
< /hello/ux/PH/src/USOURCES/java/frame/contain/ProcessResult.js
< /hello/ux/PH/src/DEMO/dir/web/Hello.java
< /hello/ux/PH/src/USOURCES/dir/web/World.java
< /hello/ux/PH/src/USOURCES/dir/web/Hey.java

I need only those lines that are having the word "USOURCES" and discard everything that is before "USOURCES". This needs to be dumped into another file , say final.lst.

So, the final.lst would be :

USOURCES/java/frame/contain/ProcessResult.js
USOURCES/dir/web/World.java
USOURCES/dir/web/Hey.java

I tried using cut command , but that is not very generic. Please help as i am new to unix.


Solution

  • sed -n 's@.*/USOURCES@USOURCES@p' temp.lst
    

    -n says do not print unless explicitly told to by p at the end. The rest is simply deleting from lines that match and printing them.