Chinaunix

标题: 如何检测每行中的某个单词若为大写,则整行输出大写? [打印本页]

作者: iocg    时间: 2014-07-17 14:15
标题: 如何检测每行中的某个单词若为大写,则整行输出大写?
有如下一段文本。

THE COMPANY BELIEVES THE LISTING WILL ENABLE IT
stockholder value Iocg by providing stockholders with
internal IOCG external GROWTH. SINCE COMMENCING
will provide it with access to lower cost capital
further DRIVE THE Company's growth IOCG create
They "take revenge" by giving the silent treatment
uncomfortable with confrontations IOCG will mask
IOCG glib. You will have a feeling that you are
The answer, IF LEWIS IS HONEST, IS VERY RICH INVES
Loeb iocg all of them BILLIONAIRE HEDGE fund managers
IOCG all of them much richer than anybody who made
of entry IOCG reside IN FLORIDA IN COLLIER or South
Scripps Media, Inc. iocG Incidentally, there were no

将其中含大写的IOCG的行,转换为整行大写??

作者: ly5066113    时间: 2014-07-17 14:22
回复 1# iocg
  1. sed '/IOCG/s/.*/\U&/' file
复制代码

作者: zerostudy    时间: 2014-07-17 14:23
  1. awk '{for(i=1;i<=NF;i++){if($i=="IOCG"){$0=toupper($0);break}}}1' u
复制代码

作者: Shell_HAT    时间: 2014-07-17 15:25
回复 3# zerostudy
  1. awk '{print $0~/\bIOCG\b/?toupper($0):$0 }' a.txt
复制代码

作者: yestreenstars    时间: 2014-07-17 15:32
  1. awk '/IOCG/{$0=toupper($0)}1'
复制代码
  1. sed '/IOCG/s/.*/\U&/'
复制代码

作者: zerostudy    时间: 2014-07-17 15:36
  1. sed -r '/\bIOCG\b/s/.*/\U&/' u
复制代码
应要加\b\b
作者: Shell_HAT    时间: 2014-07-17 15:39
回复 6# zerostudy


    -r 是没有必要的吧




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2