0

I have directory of recording with

foo - bar-202009.opus
unix - tilde-2020se.opus
stack - exchange-29328f.opus

I trying to set meta from file name for foo - bar.202009.opus (there are some inconsistency with - so easy way is scrapping -<6digitchars>.opus)

song title = foo - bar 

Using sed to scrap,

$ ls | sed 's/-[a-zA-Z0-9]*\w//g; s/.opus//g'

foo - bar
unix - tilde
stack - exchange

I use id3tag to set, synatx

id3tag --song=[tilte] [file]

I have all those in directory, so iterating with while & read,

ls | while read x; \
    do id3tag \
    $(echo \
    --song=\"$(echo $x | sed 's/-[a-zA-Z0-9]*\w//g; s/.opus//g')\"  \
    \"${x}\"
    ); \
    done

problem with above is, the spaces in input file causes id3 to interpret as another file (even when enclosed with \"${x}\")

so output right now,

foo
'bar"'
'"bar-202009.opus"'
.
.

Is there a way for i3dtag to see file with spaces as a single file.

1

2 Answers 2

0

Avoiding ls parse, one-liner.

#!/bin/sh

for file in *; do
    scrap="$(echo $file | sed 's/-[a-zA-Z0-9]*\w//g; s/.opus//g')"
    id3tag --song="${scrap}" "${f}"
done
0

I suggest that you not try to make it a one-liner:

ls | while read x; do
    x="$(echo $x | sed 's/-[a-zA-Z0-9]*\w//g; s/.opus//g')"
    id3tag --song="${x}"
done

The point annahri made about not parsing ls output is a good one, so you could instead do

for x in *.opus; do
 .... the rest is the same

With this approach, there are fewer places for the quotes to get consumed by a sub-shell or for the quotes to be passed as a literal to id3tag.

5
  • This is more of a comment than an answer, doesn't solve my problem of passing input to id3tag
    – Hisacro
    Sep 20, 2020 at 19:10
  • @Hisacro I notice that your answer is almost identical to this in terms of breaking the one-liner into multiple calls and doing the parsing before invoking id3tag. I'm glad you found it useful. Sep 20, 2020 at 21:01
  • thought it's identical, there's no way(?) to parse second argument "${file_input}" to i3tags (spaces always break as new file guess that's how the ls works). If you have figured with ls I'll accept your answer without regrets.
    – Hisacro
    Sep 21, 2020 at 12:46
  • if you think about it, whole script is pointless without file input (ie. second argument)
    – Hisacro
    Sep 21, 2020 at 12:55
  • @Hisacro point taken, I didn't notice the second parameter in your original post. Sep 21, 2020 at 21:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .