0

I am working with ffmpeg and want to automate making one big video from many smaller. I can use a list file, but each line Must Be file 'name.ext'. I can't figure out how to get sed or awk to NOT see the ' as a control character. Any way to do that?

I have tried using a variable as instead of the string file ', tried a two statement script where i set file @ then use another cmd to change the @ to ', but it fails every time

awk '{print "line @"  $0}' uselessInfo.txt >goofy2.txt
sed '/@/\'/g' goofy2.txt >goofy3.txt 

tried the sed line with " around the ' also

oguz ismail
  • 1
  • 16
  • 47
  • 69
Mike Z
  • 1
  • 2
    Where exactly do you want the single quotes added? Your post title says to prepend it, but your examples seem to have in the middle with assorted other words prepended? – Shawn May 01 '19 at 22:06
  • 2
    Did you see the section about "Automatically generate the input file" on the [help page for Concatenate](https://trac.ffmpeg.org/wiki/Concatenate)? – Benjamin W. May 01 '19 at 22:53
  • The quick and dirty fix is to change your sed command to `sed "s/@/'/g"`, but instead, you should generate `uselessInfo` with the proper quotes in the first place. Also, dirty fix probably won't work because it's missing the closing quote – it's just fixing the outermost deficiency in your attempt. – Benjamin W. May 01 '19 at 22:54

3 Answers3

1

Neither sed nor awk are seeing ' as a control character. In fact they aren't seeing the ' at all in the code you posted - the shell doesn't allow you to use single quotes inside a single quote delimited script.

Your question isn't clear. Is this what you're trying to do?

$ echo 'foo' | awk '{print "file \047" $0 "\047"}'
file 'foo'

$ echo 'foo' | sed 's/.*/file '\''&'\''/'
file 'foo'

$ echo 'foo' | sed "s/.*/file '&'/"
file 'foo'

If not then edit your question to clarify and provide a concrete example we can test against.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185
0

If you just want to add a single quote at the front of each line:

> cat test.txt
a
b
c
> sed "s/^/'/" test.txt
'a
'b
'c

You can then output this to whatever file you wish as in your example. The solution to your problem, I believe, lies in the fact that characters within single quotes on the command line are not interpreted. This means that when you try to escape a quote inside a single quoted string, this will not work and you just get a backslash in your string. Comparing this to a string bound by double quotes, we see that the backslash is interpreted before being passed to the command echo as an argument.

> echo '\'
\
> echo "\""
"
Kind Stranger
  • 1,736
  • 13
  • 18
0

another useful trick is defining single quote as a variable

$ echo "part 1" | awk -v q="'" '{print "line " q $0 q}'

line 'part 1'
karakfa
  • 66,216
  • 7
  • 41
  • 56