0

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.

6055
  • 439
  • 1
  • 4
  • 14

3 Answers3

1
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.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
1

Solution

You can use grep option -o and a glob for that.

grep -o 'USOURCES.*' /tmp/so.txt

Output:

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

Explaination

-o, --only-matching

   Print  only  the  matched  (non-empty) parts of a matching line, 
   with each such part on a separate output line.
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
1

Using awk:

awk -F'USOURCES' 'NF>1{print FS $2}' temp.lst > final.lst
John B
  • 3,566
  • 1
  • 16
  • 20