- 浏览: 2048778 次
- 性别:
- 来自: NYC
文章分类
- 全部博客 (628)
- Linux (53)
- RubyOnRails (294)
- HTML (8)
- 手册指南 (5)
- Mysql (14)
- PHP (3)
- Rails 汇总 (13)
- 读书 (22)
- plugin 插件介绍与应用 (12)
- Flex (2)
- Ruby技巧 (7)
- Gem包介绍 (1)
- javascript Jquery ext prototype (21)
- IT生活 (6)
- 小工具 (4)
- PHP 部署 drupal (1)
- javascript Jquery sort plugin 插件 (2)
- iphone siri ios (1)
- Ruby On Rails (106)
- 编程概念 (1)
- Unit Test (4)
- Ruby 1.9 (24)
- rake (1)
- Postgresql (6)
- ruby (5)
- respond_to? (1)
- method_missing (1)
- git (8)
- Rspec (1)
- ios (1)
- jquery (1)
- Sinatra (1)
最新评论
-
dadadada2x:
user模型里加上 protected def email ...
流行的权限管理 gem devise的定制 -
Sev7en_jun:
shrekting 写道var pattern = /^(0| ...
强悍的ip格式 正则表达式验证 -
jiasanshou:
好文章!!!
RPM包rpmbuild SPEC文件深度说明 -
寻得乐中乐:
link_to其实就是个a标签,使用css控制,添加一个参数: ...
Rails在link_to中加参数 -
aiafei0001:
完全看不懂,不知所然.能表达清楚一点?
"$ is not defined" 的问题怎么办
UPDATE: (05/03/2013)
当前使用:
ere’s the post on my new blog – http://rushi.vishavadia.com/blog/find-replace-across-multiple-files-in-linux/
Below is an older version of the post:
I was trying to find a solution todo a find & replace across multiple files which was purely command line based. There are plenty of scripts out there which will accomplish this but I needed a single line command. After some google searches and some experimentation I came up with this snippet.
find . -name "*.php" -print | xargs sed -i 's/foo/bar/g'
It looks a bit complicated but its quite simple. There are three components to the command:
find . -name "*.php" -print – Find all files (recursively) which has “.php” in the file and print them out. This will give you output like this:
./file.php
./includes/test.php
./classes/class.php
xargs- This command is used when you want to pass a lot of arguments to one command. xargs will combine the single line output of find and run commands with multiple
arguments, multiple times if necessary to avoid the max chars per line limit. In this case we combine xargs with sed
sed -i 's/foo/bar/g' – aka Stream Editor is a tool which should be in every sys admin’s toolkit. In this case every occurence of “foor” is replaced by “bar” in all the files found using the “find” command. Sed simply parses input and applies certain text transformations to it. There’s a lot to say about sed, you can find more at this tutorial.
This pretty much covers the core of the find & replace command. You could also open up a particular folder in an IDE and use it’s find and replace feature. But find + sed is quite fast and powerful.
当前使用:
#去掉所有的FactoryGirl. find . -type f -name *_spec.rb -print | xargs sed -ie 's/FactoryGirl\.//g'
//Seems like Linux is being far too generous. -i 's/^[[:space:]]\{11\}//g' <-- makes it look like "s/^[[:space:]]\{11\}//g" is the extension given to "-i" //baf's quotes serve to clarify to the interpreter (and to humans reading it) that there is no extension. hayne's -e is also a means with which to disambiguate. //Thus, these all work: sed -i "" 's/^[[:space:]]\{11\}//g' menu1a.sh sed -i -e 's/^[[:space:]]\{11\}//g' menu1a.sh sed -ie 's/^[[:space:]]\{11\}//g' menu1a.sh sed -i "" -e 's/^[[:space:]]\{11\}//g' menu1a.sh Makes sense.
find . -name "*.php" -print | xargs sed -i 's/foo/bar/g' $ find /home/bruno/old-friends -type f -exec sed -i 's/ugly/beautiful/g' {} \;
引用
ere’s the post on my new blog – http://rushi.vishavadia.com/blog/find-replace-across-multiple-files-in-linux/
Below is an older version of the post:
I was trying to find a solution todo a find & replace across multiple files which was purely command line based. There are plenty of scripts out there which will accomplish this but I needed a single line command. After some google searches and some experimentation I came up with this snippet.
find . -name "*.php" -print | xargs sed -i 's/foo/bar/g'
It looks a bit complicated but its quite simple. There are three components to the command:
find . -name "*.php" -print – Find all files (recursively) which has “.php” in the file and print them out. This will give you output like this:
./file.php
./includes/test.php
./classes/class.php
xargs- This command is used when you want to pass a lot of arguments to one command. xargs will combine the single line output of find and run commands with multiple
arguments, multiple times if necessary to avoid the max chars per line limit. In this case we combine xargs with sed
sed -i 's/foo/bar/g' – aka Stream Editor is a tool which should be in every sys admin’s toolkit. In this case every occurence of “foor” is replaced by “bar” in all the files found using the “find” command. Sed simply parses input and applies certain text transformations to it. There’s a lot to say about sed, you can find more at this tutorial.
This pretty much covers the core of the find & replace command. You could also open up a particular folder in an IDE and use it’s find and replace feature. But find + sed is quite fast and powerful.
发表评论
-
在ubuntu中.profile 和.bashrc的加载区别
2013-06-01 21:38 2458总之,profile不只是bash,在启动加载 bashrc是 ... -
command line tools for linux
2013-02-14 23:49 1429du -sh `ls .` for i in G M K; ... -
ubuntu 12.10 proxy install package apt-get
2013-01-31 06:47 1170#/.bashrc export http_proxy= ... -
shell script
2012-09-11 21:08 997select r.name, count(p.id) from ... -
定期清空日志文件
2012-09-11 10:04 3303一个关于如何在指定文件大于1GB后,自动删除的问题。 批处理代 ... -
查看一个进程占用了那个端口
2012-09-11 09:59 1677有时候需要在Linux下查看一个进程占用了那个端口,但是只知道 ... -
utf8 ruby1.9
2012-07-13 01:57 1285引用invalid byte sequence in utf- ... -
VIM下跳转的区别
2012-05-06 00:33 1340VIM在开tag和jumplist的时候有几个差别 经常用的 ... -
shell command
2012-04-11 21:42 875ls -l . | egrep -c '^d' ls -l . ... -
unbuntu 查看什么占着80端口
2012-01-19 12:37 1394sudo lsof -i :80 sudo nets ... -
处理僵尸进程
2011-05-27 01:45 1123#!/bin/sh kill -HUP `ps -A - ... -
ubuntu 看硬件配置
2011-05-02 02:03 5241总是忘记阿,标记一下 sudo lspci -v lshw ... -
no such file to load -- zlib
2011-04-25 23:52 2710或者提示 fatal error: zlib.h: No su ... -
新装的mysql出现无法登陆的问题 er 1405 参考下面的解决
2011-01-23 12:39 3034Installing MySQL 5.0 First we ... -
ssh无密码登入设置
2010-08-17 21:02 1357现有2台机器 1、服务器192.168.1.112 2、个人机 ... -
bash和乱码
2010-08-16 00:15 1871几个bash下配置的区别 1)/etc/profile: 此文 ... -
ubuntu 配置git服务器及其它
2010-08-15 23:46 2123update: 生产public key的时候不能按照git ... -
nohup命令让程序在后台运行-linux
2010-02-04 14:17 6972nohup ruby /sunrise/www/realwor ... -
shell 条件可能用到
2010-01-26 15:05 1484为什么不能用ruby脚本写啊,shell脚本写的俺很烦啊... ... -
shell脚本和case 使用相关的例子
2010-01-22 17:25 34255支(case与select结构) case ...
相关推荐
查找文件内容并替换
16.如何对文本文件进行查找与替换?(Visual C++编程 源代码)16.如何对文本文件进行查找与替换?(Visual C++编程 源代码)16.如何对文本文件进行查找与替换?(Visual C++编程 源代码)16.如何对文本文件进行查找...
VC++文件查找替换VC++文件查找替换VC++文件查找替换VC++文件查找替换VC++文件查找替换VC++文件查找替换VC++文件查找替换
批量查找替换文件内容软件,批量查找修改文件里面的内容,方便修改查找,有两个版本在里面
查找文本文件的内容并替换类 类里做的UTF-8的转换 ...主要参数:要替换内容文件的path,fold原字串,fnew替换字串 发现对文件操作的时候很多情况下要做文件内容的查找并替换。所以就写了这么类。可以改造成查找内容的类
支持对目录下所有文件内包含特定字符串全部查找、替换,不需打开文件,支持txt,java,word,jsp,html等等
小软件Replace Plus:为多个文本文件做内容批量替换 当我们的文本里有些相同的文本内容要替换成其他内容时,可以运用到“文本替换”功能,这一功能在诸多的文本编辑软件里都有,并不算稀奇。但是,如果你有多个文件...
matlab开发-查找和替换文件。用新文本替换文件列表中的指定文本。
SearchAndReplace 文件内容查找与替换 做项目时,我发现这东西巨好用。 支持自定义后缀,比如:*.* 、*.java 、* 分别代表:任意后缀和任意文件名的文件、任意文件名的JAVA类型文件、无后缀的所有文件
感觉网上的不理想,就自己写了一个查找替换的工具
文件按字节查找替换,外部资源可以用exeScope查找替换网上一大堆就不传了
阿宝查找替换工具是一款帮助用户快速查找指定文件夹内,指定关键词的文本,操作简单,使用方便,需要的朋友可以前来本站下载。 软件功能 1.更好的支持中文,代码里加了一些编码转换 2.输入文件目录改成选择文件...
是一款用来查找系统中所有文本内容的工具,可以全部文件格式查找,也可以指定文件格式进行查找,支持在多级子目录中进行查找,还可以在压缩文件中直接查找文本内容,支持多文件批量查找,还能对查找的内容进行替换,...
字符串查找替换,多文件字符串查找替换,批量查找多文件的某一个字符,批量替换某一个字符等。
能在所有的文件及文件夹内查找替换文件内容。
windows软件,文件内容查找工具;windows软件,文件内容查找工具
三款查找替换文件中的内容的软件,无需安装,有一个有弹出页面。 可以批量查找文件中的字符串。批量修改源代码或WORD,EXCEL文件必备
打开rtf文件,查找和替换里面的文件(VB6.0源代码编写) 打开rtf文件,查找和替换里面的字符。
全能文本批量替换工具 批量查找 批量替换 文本文件处理的好工具 强烈推荐