`

pipe in -exec

阅读更多
一个简单的例子:
将一堆的.txt文件,合并成一个文件,让每个文件的内容在合并的文件中占一行。
可能想用以下的代码来解决:
find . -name "*.txt" -exec cat {} | tr -d '\n' \; -print

但这是错误的,因为bash首先会解释|为管道,分割命令,即使加上\|也不行。
一个解决方法时使用sh命令来执行:
find . -name "*.txt" -exec sh -c "cat {} | tr -d '\n'; echo \n" \;

还可以使用-printf来输出命令,让sh执行:
find . -name "*.R" -printf "cat %p | tr -d '\n'; echo\n" | sh
2
0
分享到:
评论

相关推荐

    193_4ECH.PDF

    You can also use the exec and system functions to run other programs. However, things start diverging rapidly by operating system from this point on. In Unix, you can use the Perl function fork to ...

    线性规划的matlab代码-software_engineering:这是与深度学习相关的软件工程的仓库

    管道和输出重定向:pipe/&1/&2/>/>>/tee/tail 1.1.3 文件查找和正则表达式:which/locate/updatedb/find/grep/wc/sed 1.1.4 循环:while/for in/xargs/find -exec 1.1.5 监测系统:w/bmon/iostat/iotop 1.1.6 misc:...

    unix实验系统调用

    unix实验基础内容:系统调用assignments assignment 0: Build the linux kernel(20') step 1: get the linux kernel code before you download and compile the linux ...in CentOS, install these software using yum

    2009 达内Unix学习笔记

    集合了 所有的 Unix命令大全 ...telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss ... 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ ... 命令和参数之间必需用空格隔...

    rubix_kernel:一个简单的ARMv7内核

    pipe -创建管道。 读取fd [0],写入fd [1]。 fopen打开文件。 不完全是POSIX,因为它是非阻塞的fork克隆过程。 如果为子代,则返回值为0;如果父代,则返回子代的PID;如果错误,则返回-1。 exec用另一个程序替换该...

    linux.chm文档

    iconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding. find . -maxdepth 1 -name ...

    华中科技大学操作系统实验报告.docx

    3.一个父进程创建一个子进程,子进程通过exec系统调用执行另一个文件。各自的代码中显示不同的信息,观察其运行结果,分析两个进程并发执行的效果。 4. 编写程序创建如图所示的进程树,在每个进程中显示当前进程ID和...

    Using Perl For Web Programming.pdf

    Filling in Text Fields and Selecting List Items H Saving and Editing User-Designed Pages H G From Here G Chapter 5 Searching Searching the Full Text of Your Site Scanning Directories Using a ...

    UNIX Network Programming Volume 2(Unix网络编程卷2英文版)

    1.5 effect of fork, exec, and exit on ipc objects 9 1.6 error handling: wrapper functions 11 1.7 unix standards 13 1.8 road map to ipc examples in the text 15 1.9 summary 16 chapter 2. posix ipc...

    linux内核 0.11版本源码 带中文注释

    │ exec.c │ fcntl.c │ file_dev.c │ file_table.c │ inode.c │ ioctl.c │ Makefile │ namei.c │ open.c │ pipe.c │ read_write.c │ stat.c │ super.c │ truncate.c │ ├─include │ │ a.out.h │ ...

    莱昂氏UNIX源代码分析(全面剖析unix)PDF

    12.6.1 exec(3020) 285 12.6.2 fork(3322) 286 12.6.3 sbreak(3354) 286 12.7 文件sys2.c和sys3.c 287 12.8 文件sys4.c 287 第13章 软件中断 288 13.1 设置期望动作 288 13.2 对进程造成中断 288 13.3 作用 289 13.4...

    莱昂氏UNIX源代码分析

    12.6.1 exec(3020) 285 12.6.2 fork(3322) 286 12.6.3 sbreak(3354) 286 12.7 文件sys2.c和sys3.c 287 12.8 文件sys4.c 287 第13章 软件中断 288 13.1 设置期望动作 288 13.2 对进程造成中断 288 13.3 作用 289 13.4...

    Python3 菜鸟查询手册

    11.05 字典 in 操作符.png 11.06 字典 items() 方法.png 11.07 字典 keys() 方法.png 11.08 字典 setdefault() 方法.png 11.09 字典 update() 方法.png 11.10 字典 values() 方法.png 11.11 字典 pop() 方法....

Global site tag (gtag.js) - Google Analytics