Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

316 views
Skip to first unread message

hongy...@gmail.com

unread,
Jun 26, 2022, 11:59:24 PM6/26/22
to
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

Janis Papanagnou

unread,
Jun 27, 2022, 1:40:04 AM6/27/22
to
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

hongy...@gmail.com

unread,
Jun 27, 2022, 3:53:56 AM6/27/22
to
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
0 new messages