Chinaunix

标题: 如何遍历awk出来的整数集合文件进行sed处理 [打印本页]

作者: 只为踏雪寻梅    时间: 2011-06-28 23:52
标题: 如何遍历awk出来的整数集合文件进行sed处理
大家好:
  我有一个n.file里面是整数的集合  如下面
107
109
423
477
479
481
我想把这些整数+1 再放到sed命令去执行我的输出  想到的是expr去执行这一个+1操作  这就需要一个遍历 不太清楚这个遍历要如何写  请高手指点下!不甚感激
作者: yinyuemi    时间: 2011-06-29 00:01
回复 1# 只为踏雪寻梅
  1. echo '107
  2. 109
  3. 423
  4. 477
  5. 479
  6. 481' |sed "s/.*/expr & + 1/e"
  7. 108
  8. 110
  9. 424
  10. 478
  11. 480
  12. 482
复制代码
or :
  1. while read line
  2. do
  3. ((line++))
  4. sed "{action}"
  5. done <file
复制代码

作者: rdcwayx    时间: 2011-06-29 08:07
  1. awk '{print $1+1}' infile
复制代码

作者: kr_zhang    时间: 2011-06-29 08:09
sed "s/.*/expr & + 1/e"
这里面的 e 是不是 执行前面expr命令的意思。
作者: yinyuemi    时间: 2011-06-29 08:20
回复 4# kr_zhang


   
e
This command allows one to pipe input from a shell command into pattern space. If a substitution was made, the command that is found in pattern space is executed and pattern space is replaced with its output. A trailing newline is suppressed; results are undefined if the command to be executed contains a nul character. This is a GNU sed extension.

作者: kr_zhang    时间: 2011-06-29 08:35
回复 5# yinyuemi


  收到! 谢谢。
作者: cjaizss    时间: 2011-06-29 10:10
大家好:
  我有一个n.file里面是整数的集合  如下面
107
109
423
477
479
481
我想把这些整数+1 再 ...
只为踏雪寻梅 发表于 2011-06-28 23:52



    cat n.file|xargs -n 1 expr 1 + | sed...
作者: zooyo    时间: 2011-06-29 11:54
提示: 作者被禁止或删除 内容自动屏蔽
作者: yangyang1581    时间: 2011-06-29 12:48
sed "s/.*/expr & + 1/e" a.log
expr: 语法错误

expr: 语法错误

expr: 语法错误

expr: 语法错误
我电脑不能用这条命令
作者: yinyuemi    时间: 2011-06-29 13:34
回复 9# yangyang1581


    帖下你的:cat -A a.log
作者: cjaizss    时间: 2011-06-29 13:58
本帖最后由 cjaizss 于 2011-06-29 13:59 编辑
sed "s/.*/expr & + 1/e" a.log
expr: 语法错误

expr: 语法错误

expr: 语法错误

expr: 语法错误
...
yangyang1581 发表于 2011-06-29 12:48



    真要用sed这么去做吧
sed -r 's/\>/;/g;s/\</expr 1 + /ge'
作者: kr_zhang    时间: 2011-06-30 12:54
回复 9# yangyang1581


    和sed 的版本有关, 我的AIX 下不行, redhat下就可以,应该和GUN有关。
作者: expert1    时间: 2012-07-19 21:30
这个需要mark一下,那个sed 的e参数,找了好久没看到解释。




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