Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to extract text which matches particular fields in text file using linux commands

Tags:

linux

sed

awk

Hi below is my text file

{"Author":"john"
  "subject":"java"
  "title":"java cook book.pdf"}

{"title":"Php book.pdf"
 "Author":"Smith"
 "subject":"PHP"}

{"Author":"Smith"
"title":"Java book.pdf"}

from the above data i want to extract all titles which contains "java" word, i should get the following output

java cook book.pdf
Java book.pdf

Please suggest me

Thanks

like image 610
user2353439 Avatar asked Nov 15 '25 21:11

user2353439


1 Answers

GNU sed

sed -r '/title.*java/I!d;s/.*:.(.*).}$/\1/' file
java cook book.pdf
Java book.pdf
like image 87
Endoro Avatar answered Nov 17 '25 12:11

Endoro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!