如何将以下各项的第一个字母从大写字母转换为lowere case?
例如,sentMessage
将成为NotAttemptedCreditLimitReached
而notAttemptedCreditLimitReached
将成为SentMessage
DeliverySucceeded
DeliveryFailed
DeliveryTimedOut
NotAttemptedCreditLimitReached
NotAttemptedChargingFailure
SubscriptionFailed
SentReportSMDeliveryStatus
FailedToSendReportSMDeliveryStatus
ReportSMSucceeded
ReportSMFailed
......等等
下面的单词列表。它们只是一个文本文件。
$ cat testw
SentMessage
DeliverySucceeded
DeliveryFailed
DeliveryTimedOut
NotAttemptedCreditLimitReached
NotAttemptedChargingFailure
SubscriptionFailed
SentReportSMDeliveryStatus
FailedToSendReportSMDeliveryStatus
ReportSMSucceeded
ReportSMFailed
$ sed -i 's/[A-Z]/\L&/' testw
$ cat testw
sentMessage
deliverySucceeded
deliveryFailed
deliveryTimedOut
notAttemptedCreditLimitReached
notAttemptedChargingFailure
subscriptionFailed
sentReportSMDeliveryStatus
failedToSendReportSMDeliveryStatus
reportSMSucceeded
reportSMFailed
最初看着做notepadd ++,但对其他建议开放bash / python ......等
hostname
答案 0 :(得分:4)
如果您有gnu sed,请使用:
sed -i 's/[A-Z]/\L&/' file
[A-Z]
将匹配首个大写字母&
是模式匹配字符串的反向引用(在本例中为单个大写字母)\L
将后引用转换为小写