Awk/sed script to convert a file from camelCase to underscores

后端 未结 4 733
灰色年华
灰色年华 2020-12-30 02:49

I want to convert several files in a project from camelCase to underscore_case.

I would like to have a onliner that only needs the filename

4条回答
  •  萌比男神i
    2020-12-30 03:43

    The proposed sed answer has some issues:

    $ echo 'FooBarFB' | sed -r 's/([a-z0-9])([A-Z])/\1_\L\2/g'
    Foo_bar_fB
    

    I sugesst the following

    $ echo 'FooBarFB' | sed -r 's/([A-Z])/_\L\1/g' | sed 's/^_//'
    foo_bar_f_b
    

提交回复
热议问题