免费注册 查看新帖 |

Chinaunix

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

newbie shell question..?? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-03-10 07:43 |只看该作者 |倒序浏览
What are they means??

\ (... \)
^\(. \)
^\(. \)1
^\(. \).*\1$
^/(... \)\(... \)


They are the same meaning??

tr -s ' ' ' ' < lotsaspaces  and tr -s ' ' ' < lotsaspaces

about change the columns

file called phone book
Alice     569-2105
liz         775-2289
tony     493-3243

it use
$s/\(.*\)     \(.*\)/\2 \1/
then give this result
569-2105     Alice
775-2289     liz
493-3243     tony
Any one can explain it why??

论坛徽章:
0
2 [报告]
发表于 2003-03-10 08:28 |只看该作者

newbie shell question..??

\(          \),这是为了保存被匹配的模式
1、就是为了后来的引用,\(...\)(可以用\1来引用任意3 个字符),!
2、\(.\)是包含任意单个字符,同样可以用\1来引用,前面加^就是查寻以任意字符开头的行。
3、好像你少写了个\,应该是这样吧^\(. \)\1,和(2)一样,只不过是用\1来引用\(。\)中的字符,整个的意思是查询以任意两个相同的字符开头的 行,像aa、bb 、cc。
4、查询以任意字符开头,中间包含零个或多个字符,且行尾以与行首相同的单个字符结束的行,像aa、aba、abdddda。
5、好象也写错了吧,应该是^\(... \)\(... \) 这样吧,查询以相同的两组(每组包含任意3个字符)字符开头的行,像abcabc、bcdbcd.

论坛徽章:
0
3 [报告]
发表于 2003-03-10 08:41 |只看该作者

newbie shell question..??

$s/\(.*\)空格\(.*\)/\2 \1/
又发现一个me知道的(rob)!
这就是查询以任意零个或多个字符开头,且以空格作为分割符,后面跟着零个或多个字符的行。例如第一行:
用这个\(.*\) 找到了569-2150(后面可以用\1来引用),然后是空格,接下来用\(.*\)又找到了Alice(后面可以用\2来引用)。
所以,结果就变成了下面的。
假如上面的行是Alice 569-2150  nmgzw,那结果就是
569-2150 nmgzw Alice

论坛徽章:
0
4 [报告]
发表于 2003-03-10 08:48 |只看该作者

newbie shell question..??

tr -s ' ' ' ' < lotsaspaces and tr -s ' ' ' < lotsaspaces
这一行我没看明白,不知道那些引号是单引号还是但引号包含的双引号,还是单引号里边包含的许多空格呢?可能是我的显示问题吧!
tr -s ' ' ' ' < lotsaspaces ,如果是两个单引号,可能是表示把lotsaspaces中的多个空格替换成一个空格;
tr -s ' ' ' < lotsaspaces ,好像是把多个连续出现的单引号替换为一个。

----------------------------------------
哎~~~
还是请高手们解答吧

论坛徽章:
0
5 [报告]
发表于 2003-03-10 12:51 |只看该作者

newbie shell question..??

原帖由 "nmgzw" 发表:
tr -s ' ' ' ' < lotsaspaces and tr -s ' ' ' < lotsaspaces
这一行我没看明白,不知道那些引号是单引号还是但引号包含的双引号,还是单引号里边包含的许多空格呢?可能是我的显示问题吧!
tr -s ' ' ' ' ..........


引号之間是Space, 不是双引号...

thx

论坛徽章:
0
6 [报告]
发表于 2003-03-11 01:27 |只看该作者

newbie shell question..??

原帖由 "kinux"][quote:d3fa4e13e9="nmgzw" 发表:
tr -s ' ' ' ' < lotsaspaces and tr -s ' ' ' < lotsaspaces
这一行我没看明白,不知道那些引号是单引号还是但引号包含的双引号,还是单引号里边包含的许多空格呢?可能是我的显示问题吧!
tr -s ' ' ' ' ..........


引号之間是Space, 不是双引号...

thx[/quote]


tr -s ' ' ' ' < lotsaspaces  

-s  replace instances of repeated characters with a single character.

hence after running this command, only single space left in the text file lotsaspace.

tr -s ' ' ' < lotsaspaces

is it a typo? seems should be

tr -s ' ' '' < lotsaspaces

it takes same effect, althogh there is no space between the second quote pair.

论坛徽章:
0
7 [报告]
发表于 2003-03-12 08:14 |只看该作者

newbie shell question..??

哦,是这样啊!
这回,光明使者肯定明白了!

论坛徽章:
0
8 [报告]
发表于 2003-03-12 08:55 |只看该作者

newbie shell question..??

Thanks all...

论坛徽章:
0
9 [报告]
发表于 2003-03-12 09:13 |只看该作者

newbie shell question..??

^=^
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP