有以下源文件 a.txt:
# This is a file
// Comments
somechars
somechars,somechar
somechars,somechars,somechars
需求:
在有且只有一个逗号的情况下,在行末插入指定字符串。 在有 2 个逗号的情况下,在第二个逗号前插入指定字符串。
输出效果 output.txt:
# This is a file
// Comments
somechars
somechars,somechar,STRTOBEINSERT
somechars,somechars,STRTOBEINSERT,somechars
求教如何实现这个效果,使用 sed/awk 都可以,多谢🙏
# This is a file
// Comments
somechars
somechars,somechar
somechars,somechars,somechars
需求:
在有且只有一个逗号的情况下,在行末插入指定字符串。 在有 2 个逗号的情况下,在第二个逗号前插入指定字符串。
输出效果 output.txt:
# This is a file
// Comments
somechars
somechars,somechar,STRTOBEINSERT
somechars,somechars,STRTOBEINSERT,somechars
求教如何实现这个效果,使用 sed/awk 都可以,多谢🙏