• bash: /usr/bin/sed: Argument list too long

    From hongyi.zhao@gmail.com@21:1/5 to All on Sun Jun 26 20:59:18 2022
    I've two files, named as "__tmp.symbols" and "gap.tmLanguage" respectively, and they can be retrieved from here [1]. When I try to run the following sed command using these two files, an error will be triggered as follows:

    $ sed -E -i "s/^(\s*<string>\\\b\().*IsGroup.*(\)\\\b<\/string>$)/\1$(cat ./__tmp.symbols)\2/g" gap.tmLanguage
    bash: /usr/bin/sed: Argument list too long

    Any hints for fixing it?

    [1] https://github.com/hongyi-zhao/temp/tree/master/sed

    Regards,
    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to hongy...@gmail.com on Mon Jun 27 07:39:54 2022
    On 27.06.2022 05:59, hongy...@gmail.com wrote:
    I've two files, named as "__tmp.symbols" and "gap.tmLanguage" respectively, and they can be retrieved from here [1]. When I try to run the following sed command using these two files, an error will be triggered as follows:

    $ sed -E -i "s/^(\s*<string>\\\b\().*IsGroup.*(\)\\\b<\/string>$)/\1$(cat ./__tmp.symbols)\2/g" gap.tmLanguage
    bash: /usr/bin/sed: Argument list too long

    Any hints for fixing it?

    Obviously the contents of file __tmp.symbols are far too many so
    that $(cat ./__tmp.symbols) will expand to a too long line.

    My guess is that you wanted to do something different than putting
    the whole content of a file into a sed _substitution argument_?

    Anyway, to fix that use a more appropriate approach, like matching
    the pattern and printing the contents at the matched place. A tool
    like awk (for example) will provide you with that solution.

    Janis


    [1] https://github.com/hongyi-zhao/temp/tree/master/sed

    Regards,
    HZ


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Janis Papanagnou on Mon Jun 27 00:53:50 2022
    On Monday, June 27, 2022 at 1:40:04 PM UTC+8, Janis Papanagnou wrote:
    On 27.06.2022 05:59, hongy...@gmail.com wrote:
    I've two files, named as "__tmp.symbols" and "gap.tmLanguage" respectively, and they can be retrieved from here [1]. When I try to run the following sed command using these two files, an error will be triggered as follows:

    $ sed -E -i "s/^(\s*<string>\\\b\().*IsGroup.*(\)\\\b<\/string>$)/\1$(cat ./__tmp.symbols)\2/g" gap.tmLanguage
    bash: /usr/bin/sed: Argument list too long

    Any hints for fixing it?
    Obviously the contents of file __tmp.symbols are far too many so
    that $(cat ./__tmp.symbols) will expand to a too long line.

    My guess is that you wanted to do something different than putting
    the whole content of a file into a sed _substitution argument_?

    Anyway, to fix that use a more appropriate approach, like matching
    the pattern and printing the contents at the matched place. A tool
    like awk (for example) will provide you with that solution.

    Thank you for your comment. According to your analysis and advice, I came up with the following method:

    $ awk 'FNR==NR { a = $0; next } match($0,/^(\s*<string>\\b\().*IsGroup.*(\)\\b<\/string>$)/,c) {print c[1] a c[2]; next } 1 ' __tmp.symbols gap.tmLanguage > gap.tmLanguage2

    Janis

    Yours,
    HZ


    [1] https://github.com/hongyi-zhao/temp/tree/master/sed

    Regards,
    HZ


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)