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

Extract a part of names before the start of a patern in linux?

I can list all files ls *.nc

 kjkh_lkm_kkkkk_abc_195101-196012.nc
 kjkh_lkm_kkkkk_abc_198101-196012.nc
 LM_lkm_kjjkk_abc_196101-196012.nc
 kjkh_lkm_kjjkk_abc_196101-196012.nc
 SAM_lkm_abc_196101-196012.nc
 kjk_lkm_abc_196101-196012.nc

However, I need to extract the parts before _abc ? if more than one, just ignore

 kjkh_lkm_kkkkk
 LM_lkm_kjjkk
 kjkh_lkm_kjjkk
 SAM_lkm
 kjk_lkm

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

>Solution :

Here:

ls *.nc|sed -E 's/_abc.*//'|sort|uniq > newfile
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