command line - keep only files with the same basename - Ask Ubuntu


how can keep .txt files in both imgur/images/vase imgur/comments/vase pertain .jpeg files in image folder of vase?

mona@pascal:~/computer_vision/imgur/images$ ls vase/ 09pczop.jpeg  aak8xnc.jpeg  bmlemqv.jpeg  fyjdysw.jpeg  jllgk86.jpeg  p0eqil6.jpeg  r5cwq2z.jpeg  uyqdakx.jpeg  wzvdvuv.jpeg  yojy83l.jpeg 5bsml.jpeg    aepd0fv.gif   cxenf98.jpeg  gwznimv.jpeg  ndkcsnv.jpeg  p6uca4a.jpeg  t1pvv.jpeg    vegoghz.jpeg  xagoy.jpeg    zdvstew.png 7iimf9n.jpeg  b6l0zwn.gif   ee8uepa.png   huzljjr.jpeg  ouwwy47.jpeg  qcr4c2x.jpeg  turgwyf.jpeg  vpcmgtp.gif   yibyip7.jpeg  zetwdul.png 7mk599e.jpeg  bl9b5ej.jpeg  egflbgj.jpeg  iyepkmc.jpeg  ouxgilj.png   r4edalx.png   umzke2r.gif   wk7ejug.gif   yimivh4.jpeg mona@pascal:~/computer_vision/imgur/images$ ls ../comments/vase/ 09pczop.txt  7mk599e.txt  b6l0zwn.txt  cxenf98.txt  fyjdysw.txt  iyepkmc.txt  ouwwy47.txt  p6uca4a.txt  r5cwq2z.txt  umzke2r.txt  vpcmgtp.txt  xagoy.txt    yojy83l.txt 5bsml.txt    aak8xnc.txt  bl9b5ej.txt  ee8uepa.txt  gwznimv.txt  jllgk86.txt  ouxgilj.txt  qcr4c2x.txt  t1pvv.txt    uyqdakx.txt  wk7ejug.txt  yibyip7.txt  zdvstew.txt 7iimf9n.txt  aepd0fv.txt  bmlemqv.txt  egflbgj.txt  huzljjr.txt  ndkcsnv.txt  p0eqil6.txt  r4edalx.txt  turgwyf.txt  vegoghz.txt  wzvdvuv.txt  yimivh4.txt  zetwdul.txt  mona@pascal:~/computer_vision/imgur/images/vase$ ls *jpeg 09pczop.jpeg  7mk599e.jpeg  bmlemqv.jpeg  fyjdysw.jpeg  iyepkmc.jpeg  ouwwy47.jpeg  qcr4c2x.jpeg  turgwyf.jpeg  wzvdvuv.jpeg  yimivh4.jpeg 5bsml.jpeg    aak8xnc.jpeg  cxenf98.jpeg  gwznimv.jpeg  jllgk86.jpeg  p0eqil6.jpeg  r5cwq2z.jpeg  uyqdakx.jpeg  xagoy.jpeg    yojy83l.jpeg 7iimf9n.jpeg  bl9b5ej.jpeg  egflbgj.jpeg  huzljjr.jpeg  ndkcsnv.jpeg  p6uca4a.jpeg  t1pvv.jpeg    vegoghz.jpeg  yibyip7.jpeg 

for example want have:

09pczop.txt  7mk599e.txt  bmlemqv.txt  fyjdysw.txt  iyepkmc.txt  ouwwy47.txt  qcr4c2x.txt  turgwyf.txt  wzvdvuv.txt  yimivh4.txt 5bsml.txt    aak8xnc.txt  cxenf98.txt  gwznimv.txt  jllgk86.txt  p0eqil6.txt  r5cwq2z.txt  uyqdakx.txt  xagoy.txt    yojy83l.txt 7iimf9n.txt  bl9b5ej.txt  egflbgj.txt  huzljjr.txt  ndkcsnv.txt  p6uca4a.txt  t1pvv.txt    vegoghz.txt  yibyip7.txt 

left in imgur/comments folder.

additionally have these folders:

mona@pascal:~/computer_vision/imgur/images$ ls aeroplane     baseball glove  broccoli  cell phone  dining table  frisbee   keyboards   motorcycles    plants        skateboard   teddy bear     trains airplane      bear            bus       chair       dog           giraffe   kite        mouse          refrigerator  ski          tennis racket  truck airplanes     bears           cake      chairs      dogs          giraffes  knife       orange         remote        skis         tie            trucks apple         bench           cakes     clock       donut         handbag   laptop      oranges        sandwich      snowboard    toaster        tv apples        bird            car       clocks      doughnut      horse     laptops     oven           sandwiches    spoon        toilet         umbrella backpack      birds           carrot    couch       elephant      horses    microwave   parking meter  scissors      sports ball  toilets        vase banana        book            cars      cow         elephants     hotdog    motorbike   person         sheep         stop sign    toothbrush     wine glass bananas       books           cat       cows        fire hydrant  hotdogs   motorbikes  pizza          sink          suitcase     traffic light  zebra baseball bat  bowl            cats      cup         fork          keyboard  motorcycle  plant          sinks         surfboard    train          zebras 

this python script did job:

import os.path osp import os import re   directory in os.listdir('images'):     files = [f f in os.listdir('images/'+directory+'/') if not re.match(r'([a-za-z]|[0-9])+.*\.jpeg', f)]      f in files:         complete_file_path = 'comments/'+ directory+'/'+f[:-4]+'.txt'         if osp.exists(complete_file_path):             os.remove(complete_file_path) 

Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User