如何将空格更改为下划线和小写一切?

Vij*_*jay 0 shell perl awk sed

我有一个文本文件,其中包含:

Cycle code
Cycle month
Cycle year
Event type ID
Event ID
Network start time
Run Code Online (Sandbox Code Playgroud)

我想改变这个文本,以便当有空间时,我想用一个替换它_.之后,我希望字符小写字母如下:

cycle_code
cycle_month
cycle_year
event_type_id
event_id
network_start_time
Run Code Online (Sandbox Code Playgroud)

我怎么能做到这一点?

Ada*_*ire 12

另一个Perl方法:

perl -pe 'y/A-Z /a-z_/' file
Run Code Online (Sandbox Code Playgroud)


mou*_*iel 11

tr 独自工作:

tr ' [:upper:]' '_[:lower:]' < file
Run Code Online (Sandbox Code Playgroud)