I had wanted to edit the txt files of videoA and videoB only if the movs files names contains the namespace -test

For eg.

        |- videoA_v001_test.mov
        |- videoA_v001_info.txt
        |- videoB_v001_test.mov
        |- videoB_v001_info.txt
        |- videoC_v002.mov
        |- videoC_v002_info.txt

Above, I want to edit videoDir/videoA/videoA_v001_info.txt and videoDir/videoB/videoB_v001_info.txt but not videoC_v002_info.txt since the corresponding .mov file name doesn't contain test.

I come up with the command - find -name "*.mov" | grep -rn "test" | find -name "*.txt", find -name "*.mov" | grep -rn "test" does indeed lists out the 2 files that fulfills the condition (videoA and videoB). I added infind -name "*.txt"` as I had thought it will filter it down to the txt files within the output results, however I was wrong as it is still listing all the txt files

  • There is no test in your example command. grep -r doesn't make sense if grep operates on files. grep doesn't read its search files from stdin. I have no idea what the find call is supposed to do. – Hauke Laging Jan 30 '15 at 3:06
  • There is a typo in my code. What I really wanted to achieve is to edit .txt files only if the mov files within their directories contains test in the file naming. – dissidia Jan 30 '15 at 3:10
  • 1
    ... so why not just find -name '*test*.mov'? – steeldriver Jan 30 '15 at 4:00
  • @steeldriver I am using the mov file naming as one of the condition to narrow my search. So if that condition is fulfilled, I will then need to locate the .txt file within and edit that txt file. – dissidia Jan 30 '15 at 6:34

With zsh:

vi ./**/*_test.mov(.s:_test.mov:_info.txt:)
  • I keep getting Badly placed ()'s. – dissidia Jan 30 '15 at 8:06
  • @dissidia as I said, that's zsh syntax. So you need to enter that at the prompt of that shell. – Stéphane Chazelas Jan 30 '15 at 8:27

You need something like

find . -name "*.mov" -exec grep test {} + | sed -n 's/^\([^:]*\):.*$/\1/p' | xargs -d \\n -n 1 $EDITOR

for opening one file at a time



for opening them simultaneously

(assuming the file names do not contain a colon)

  • It doesn't seems to work? But even so why is it grep mov? – dissidia Jan 30 '15 at 3:25

Your Answer

