Chinaunix

标题: 在linux中怎样在一个文档中查找一个字符串呢? [打印本页]

作者: congcn    时间: 2005-01-28 16:14
标题: 在linux中怎样在一个文档中查找一个字符串呢?
在linux中怎样在一个文档中查找一个字符串呢?
谢谢!
作者: 寂寞烈火    时间: 2005-01-28 16:25
标题: 在linux中怎样在一个文档中查找一个字符串呢?
grep,sed,awk,均可
RE:
\<string\>;
作者: congcn    时间: 2005-01-28 16:30
标题: 在linux中怎样在一个文档中查找一个字符串呢?
楼上你好?
我是一新手有很多东西还不知道,
如果我要查找文件:greip.c 中字符top20
并把top20改为top100 ,
应该怎样做呢?
谢谢!
作者: 寂寞烈火    时间: 2005-01-28 16:42
标题: 在linux中怎样在一个文档中查找一个字符串呢?
原帖由 "congcn" 发表:
楼上你好?
我是一新手有很多东西还不知道,
如果我要查找文件:greip.c 中字符top20
并把top20改为top100 ,
应该怎样做呢?
谢谢!

  1. sed -i 's/top20/top100/g' greip.c
复制代码

作者: congcn    时间: 2005-01-28 16:56
标题: 在linux中怎样在一个文档中查找一个字符串呢?
出现以下错误:
[root@proserver bandwidthd-1.2.1b]# sed -i's/top20/top100/g'graph.c
sed: invalid option -- i
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

  -n, --quiet, --silent
                 suppress automatic printing of pattern space
  -e script, --expression=script
                 add the script to the commands to be executed
  -f script-file, --file=script-file
                 add the contents of script-file to the commands to be e
      --help     display this help and exit
  -V, --version  output version information and exit

If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret.  All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.

E-mail bug reports to: bug-gnu-utils@gnu.org .
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
[root@proserver bandwidthd-1.2.1b]# sed -i s/top20/top100/g graph.c
sed: invalid option -- i
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

  -n, --quiet, --silent
                 suppress automatic printing of pattern space
  -e script, --expression=script
                 add the script to the commands to be executed
  -f script-file, --file=script-file
                 add the contents of script-file to the commands to be e
      --help     display this help and exit
  -V, --version  output version information and exit

If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret.  All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.

E-mail bug reports to: bug-gnu-utils@gnu.org .
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
作者: 寂寞烈火    时间: 2005-01-28 16:58
标题: 在linux中怎样在一个文档中查找一个字符串呢?
原帖由 "congcn"]le 发表:
...

  -n, --quiet, --silent
                 suppress automatic printing of pattern space
  -e script, --expression=script
                 add the script to the commands to be executed
  -f..........

那是sed版本的问题!
这样:

  1. vim -e -s -c ":%s/top20/top100/g" -c ":wq!" urfile
复制代码

作者: congcn    时间: 2005-01-28 17:28
标题: 在linux中怎样在一个文档中查找一个字符串呢?
还是错误,你那个:是分号还是冒号呢?
作者: stonestar    时间: 2005-01-28 17:29
标题: 在linux中怎样在一个文档中查找一个字符串呢?
长见识
作者: 寂寞烈火    时间: 2005-01-28 17:38
标题: 在linux中怎样在一个文档中查找一个字符串呢?
[quote]原帖由 "congcn"]还是错误,你那个:是分号还是冒号呢?[/quote 发表:

:
作者: congcn    时间: 2005-01-28 17:43
标题: 在linux中怎样在一个文档中查找一个字符串呢?
urfile  这个是不是要查找的文件吗?
作者: 寂寞烈火    时间: 2005-01-28 17:52
标题: 在linux中怎样在一个文档中查找一个字符串呢?
[quote]原帖由 "congcn"]urfile  这个是不是要查找的文件吗?[/quote 发表:

作者: blue_stone    时间: 2005-01-28 19:37
标题: 在linux中怎样在一个文档中查找一个字符串呢?
  1. sed -i's/top20/top100/g'graph.c
复制代码

-i 和'之间应该有空格的
'和graph之间也应该有空格的。




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