Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to do a custom "grep" in linux terminal

Suppose I have file which contains only a text like below:

Test transition to drned-internal-asr9k-rt24711
   load drned-internal-asr9k-rt24711
   commit**

Now on the terminal if I do

cat filename | grep load

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I would get output something like

load drned-internal-asr9k-rt24711

But how can I modify my grep command to get output as

drned-internal-asr9k-rt24711.txt

i.e. remove "load " and add ".txt" at the end. So how to do that??

>Solution :

May be not the best solution but :

cat | grep load | cut -c4- | sed 's/$/.txt/'

cut -c4- will delete the 4 first characters

sed 's/$/.txt/' will add the ".txt" at the end of output

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading