免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2264 | 回复: 11
打印 上一主题 下一主题

[文本处理] 对所有程序文件的字符都转换为小写的脚本,有一个问题,请大家帮忙。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-29 13:11 |只看该作者 |倒序浏览
脚本如下:
  1. #!/bin.bash

  2. find /cygdrive/d/max/ -type f -name *.html > list.txt

  3. for i in $(cat list.txt)
  4. do
  5. cat "$i" | tr '[A-Z]' '[a-z]' > "$i"
  6. echo $i
  7. done
复制代码
list.txt如下:
  1. /cygdrive/d/max/basicDo.html
  2. /cygdrive/d/max/bdzx/app/expepf_return.html
  3. /cygdrive/d/max/bdzx/applyep - 副本.html
复制代码
脚本执行到/cygdrive/d/max/bdzx/applyep - 副本.cfm这个文件就过不去了。原因是有空格,for又分出来了-和副本.html。请问大家,在for中怎样把/cygdrive/d/max/bdzx/applyep - 副本.html这一行变成一个变量呢?另外,转换所有程序文件大小写有没有其他办法?不吝赐教,谢谢了。

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
2 [报告]
发表于 2013-05-29 13:33 |只看该作者
  1. find /cygdrive/d/max/ -type f -name *.html > list.txt

  2. while read i
  3. do
  4. cat "${i}" | tr '[A-Z]' '[a-z]' > "${i}"
  5. echo ${i}
  6. done < list.txt
复制代码

论坛徽章:
0
3 [报告]
发表于 2013-05-29 13:34 |只看该作者
哇,谢谢了。我试试

论坛徽章:
5
未羊
日期:2014-08-04 16:15:21天秤座
日期:2014-08-13 13:52:372015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:56:112015亚冠之浦和红钻
日期:2015-06-29 15:30:48
4 [报告]
发表于 2013-05-29 13:38 |只看该作者
  1. echo "ABcdEF"|sed 's/[A-Z]/\l&/g'
复制代码

论坛徽章:
0
5 [报告]
发表于 2013-05-29 13:49 |只看该作者
你好的,你的sed我没看明白,请指导一下吧。

回复 4# dn833


   

论坛徽章:
48
15-16赛季CBA联赛之青岛
日期:2021-01-07 13:41:2315-16赛季CBA联赛之上海
日期:2020-12-01 18:02:0720周年集字徽章-20	
日期:2020-10-28 14:14:2620周年集字徽章-20	
日期:2020-10-28 14:04:3015-16赛季CBA联赛之天津
日期:2020-10-18 22:51:412016猴年福章徽章
日期:2016-02-18 15:30:3415-16赛季CBA联赛之北控
日期:2015-12-22 13:30:48操作系统版块每日发帖之星
日期:2015-12-07 06:20:00操作系统版块每日发帖之星
日期:2015-09-04 06:20:002015亚冠之德黑兰石油
日期:2015-08-05 18:46:082015年亚洲杯之巴勒斯坦
日期:2015-04-19 10:42:502015年亚洲杯之巴林
日期:2015-04-09 08:03:23
6 [报告]
发表于 2013-05-29 13:54 |只看该作者
sed的那是正则了~不过挺好用

论坛徽章:
0
7 [报告]
发表于 2013-05-29 13:59 |只看该作者
本帖最后由 灿烂小猪 于 2013-05-29 14:00 编辑

回复 6# lbseraph


是的,sed s/[A-Z]/匹配大写字母\l&这一块没看明白。\l是把&(匹配到的大写字母)转为小写么?   

论坛徽章:
48
15-16赛季CBA联赛之青岛
日期:2021-01-07 13:41:2315-16赛季CBA联赛之上海
日期:2020-12-01 18:02:0720周年集字徽章-20	
日期:2020-10-28 14:14:2620周年集字徽章-20	
日期:2020-10-28 14:04:3015-16赛季CBA联赛之天津
日期:2020-10-18 22:51:412016猴年福章徽章
日期:2016-02-18 15:30:3415-16赛季CBA联赛之北控
日期:2015-12-22 13:30:48操作系统版块每日发帖之星
日期:2015-12-07 06:20:00操作系统版块每日发帖之星
日期:2015-09-04 06:20:002015亚冠之德黑兰石油
日期:2015-08-05 18:46:082015年亚洲杯之巴勒斯坦
日期:2015-04-19 10:42:502015年亚洲杯之巴林
日期:2015-04-09 08:03:23
8 [报告]
发表于 2013-05-29 14:10 |只看该作者
本帖最后由 lbseraph 于 2013-05-29 14:10 编辑
灿烂小猪 发表于 2013-05-29 13:59
回复 6# lbseraph


对的,而\u是把匹配到的小写转换成大写。

参考链接:
http://www.cnblogs.com/cbscan/articles/2277351.html

论坛徽章:
0
9 [报告]
发表于 2013-05-29 14:51 |只看该作者
晓得了,谢谢哈。

论坛徽章:
5
未羊
日期:2014-08-04 16:15:21天秤座
日期:2014-08-13 13:52:372015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:56:112015亚冠之浦和红钻
日期:2015-06-29 15:30:48
10 [报告]
发表于 2013-05-29 15:11 |只看该作者
回复 5# 灿烂小猪


    把所有大写字母变成小写。就这一个l=lowercase
用info sed命令,第3.5章节s替换参数里有详细介绍
  1. 3.5 The `s' Command
  2. ===================

  3. The syntax of the `s' (as in substitute) command is
  4. `s/REGEXP/REPLACEMENT/FLAGS'.  The `/' characters may be uniformly
  5. replaced by any other single character within any given `s' command.
  6. The `/' character (or whatever other character is used in its stead)
  7. can appear in the REGEXP or REPLACEMENT only if it is preceded by a `\'
  8. character.

  9.    The `s' command is probably the most important in `sed' and has a
  10. lot of different options.  Its basic concept is simple: the `s' command
  11. attempts to match the pattern space against the supplied REGEXP; if the
  12. match is successful, then that portion of the pattern space which was
  13. matched is replaced with REPLACEMENT.

  14.    The REPLACEMENT can contain `\N' (N being a number from 1 to 9,
  15. inclusive) references, which refer to the portion of the match which is
  16. contained between the Nth `\(' and its matching `\)'.  Also, the
  17. REPLACEMENT can contain unescaped `&' characters which reference the
  18. whole matched portion of the pattern space.  Finally, as a GNU `sed'
  19. extension, you can include a special sequence made of a backslash and
  20. one of the letters `L', `l', `U', `u', or `E'.  The meaning is as
  21. follows:

  22. `\L'
  23.      Turn the replacement to lowercase until a `\U' or `\E' is found,

  24. `\l'
  25.      Turn the next character to lowercase,

  26. `\U'
  27.      Turn the replacement to uppercase until a `\L' or `\E' is found,

  28. `\u'
  29.      Turn the next character to uppercase,

  30. `\E'
  31.      Stop case conversion started by `\L' or `\U'.
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP