如何将列表中每个单词的首字母从大写转换为小写?

时间:2017-11-13 20:10:01

标签: python bash notepad++

如何将以下各项的第一个字母从大写字母转换为lowere case?

例如,sentMessage将成为NotAttemptedCreditLimitReachednotAttemptedCreditLimitReached将成为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 ......等

EDIT1 - 解决方案

hostname

1 个答案:

答案 0 :(得分:4)

如果您有gnu sed,请使用:

sed -i 's/[A-Z]/\L&/' file
  • [A-Z]将匹配首个大写字母
  • &是模式匹配字符串的反向引用(在本例中为单个大写字母)
  • \L将后引用转换为小写