`

Search and replace files in linux

阅读更多

1. How to use child commands with find ?

     find . -name classes -exec rm -r -f {} \ ;

     Please note there is a blank between {} and \;

 

2. How to use grep ?

     grep [options] PATTERN [FILES]

 

     Recursively search

     grep -r string_pattern *

 

3. How to use locate to find file?

     updatedb

     locate **/*.xml

 

4. How to find which jar constians the specified file?

     find . -name '*.jar' -exec unzip -l {} \; | grep 'Access.java \|Archive:'

     find . -name '*.jar' -exec unzip -l {} \; | grep 'Access.java\|Archive:' | sed 's#\(.*Access.java.*\)#\x1b[1;31m\1\x1b[1;37m#'

 

5.How to replace the text in a file?

     sed -in-place -e 's/are/were/g' test.txt

 

6. How to replace the text in a folder?

    find . -name "*.txt" -exec sed -in-place -e 's/are/were/g' {} \;

 

7. \ is the escape char.So if you want to replace C:\Windows with D:\Windows

    sed -in-place -e 's/C:\/windows/D:\/Widnows/g' test.txt

 

Reference

 

http://www.linuxsir.org/main/?q=node/137

http://blog.csdn.net/chaiqi/archive/2007/03/05/1521276.aspx

分享到:
评论

相关推荐

    Wiley.Publishing.Fedora.Linux.Toolbox.1000+.Commands.for.Fedora.CentOS.and.Red.Hat.Power.Users.and.Red.Hat.Power.Users.2008.pdf

    - **Search and Replace**: Finding and replacing text within files. - **Advanced Features**: Using features like macros, splits, and plugins. #### Appendix B: Shell Special Characters and Variables ...

    UE(官方下载)

    In this tutorial, we'll cover some of the basics of Unicode-encoded text and Unicode files, and how to view and manipulate it in UltraEdit. Search and delete lines found UEStudio and UltraEdit provide...

    Practical Vim: Edit Text at the Speed of Thought

    Search inside multiple files, then run Vim's substitute command on the result set for a project-wide search and replace. All without installing a single plugin! You'll learn how to navigate text ...

    esp-idf-v3.2.zip

    Replace PORT with the name of your serial port (like COM3 on Windows, /dev/ttyUSB0 on Linux, or /dev/cu.usbserial-X on MacOS. If the -p option is left out, idf.py flash will try to flash the first ...

    Senfore_DragDrop_v4.1

    doesn't extract the files and the files thus can't be copied/moved. This is caused by a quirk in WinZip; Apparently WinZip doesn't like IDataObject.GetData to be called before IDropTarget.Drop is ...

    MADEDIT 多标签

    * Regular Expression search & replace (by using Boost.Xpressive). * Opens multiple files on single instance. * Supports syntax-highlighting of many programming languages, e.g. awk, C/C++, CSS, diff/...

    Linux软件包管理

    此时可以使用 `--replacefiles` 来强制安装并替换文件。 3. **文件权限问题**: - 在安装或更新软件包时,如果遇到文件权限问题,确保运行命令的用户具有足够的权限。通常使用 `sudo` 命令来获取管理员权限。 4. ...

    Linux Shell编程(基础教程

    sed 's/pattern/replacement/' file # Replace pattern with replacement in file awk -F',' '{print $1 "," $3}' file.txt # Extract columns using comma as separator ``` 这些命令构成了 Shell 脚本的基本组成...

    BobBuilder_app

    This means that you do a binary search in the page list in log M time and get the value in O(1) time within a page. RaptorDB starts off by loading the page list and it is good to go from there and...

    从文本文件中查找字符串

    在Windows系统中,`Find`或`Find and Replace`命令也可以实现此功能。 在大量文件中查找字符串时,效率就显得尤为重要。这就需要用到命令行工具,如在Windows中的`findstr`命令,Linux或Unix环境下的`grep`命令。...

    acpi控制笔记本风扇转速

    methods are now completely parsed and executed in a single pass. This improves overall interpreter performance by ~25%, reduces code size, and reduces CPU stack use. (Valery Podrezov + interpreter ...

    DebuggingWithGDB 6.8-2008

    2 Getting In and Out of gdb . . . . . . . . . . . . . . . . 11 2.1 Invoking gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Choosing Files . . . ....

    练习-python:Python学习程序

    getsysinfo.py提供有关系统的基本信息search_replace.py在文件中搜索特定模式,成功后进行备份并追加到同一文件中find_duplicates.py列出指定文件夹中的重复文件filechecksum.py使用校验和比较文件list_files_dirs

    Reasons_to_migrate_to_Delphi_XE2_White_Paper_Final.pdf

    **搜索与替换(Search and Replace)** 搜索功能得到了增强,支持更复杂的搜索模式,如正则表达式,使查找和替换代码片段更加高效。 **重构与单元测试(Refactoring & Unit Testing)** 重构工具允许安全地修改...

    计算机专业英语词汇.pdf

    例如:“Search for the word in the dictionary”(在字典中搜索这个单词)。 84. make: 制造。创建、产生。例如:“Make a copy of the file”(复制文件)。 85. right: 右。与左边相对的一侧。例如:“Click ...

    grub4dos-V0.4.6a-2017-02-04更新

    3.two variables boot_drive and install_partition can be preset to a value before transferring control to grub4dos. (tinybit) 4.修正屏蔽 map 信息。(yaya) 2014-10-09(yaya) 1.屏蔽 map 信息。 2014...

    Source_Insight教程及技巧

    5. 文件同步:有时候可能会出现明明定义了的函数或者变量,却仍然是小黑字,这时你可以点击 Project 菜单->Synchronize Files,让文件重新同步一下。 6. 前后跳转:工具栏上有两个蓝黑色的向前、向后图标,它可以让...

    PHP基础教程 是一个比较有价值的PHP新手教程!

    $a and $b :与 $a xor $b :异或 (当$a或$b为true时为true,两者一样时为false) ! $a :非 比较运算符有: $a == $b :相等 $a != $b :不等 $a $b :小于 $a $b :小于等于 $a > $b :大于 $a >= $b :大于等于 ...

    Qt Creator 的安装和hello world 程序+其他程序的编写--不是一般的好

    窗口”,在其属性窗口中将其objectName 改为enterBtn,在下面的Signals and slots editor 中进行信号和槽的关联,其中,Sender 设为enterBtn,Signal 设为clicked(),Receive 设为myDlg,Slot 设为accept()。这样就...

Global site tag (gtag.js) - Google Analytics