破折号 e(-e) 在 sed 命令中是什么意思? [英] what does dash e(-e) mean in sed commands?

查看:51
本文介绍了破折号 e(-e) 在 sed 命令中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 sed 新手,总是对输入文件执行一个命令,最近我尝试使用 "-e" 来处理多个命令,但我不知道它是如何工作的,默认打印很烦人,所以我无法弄清楚命令的执行顺序.

I am new to sed, and always execute one command on an input file, recently I try to use "-e" to work on multiple commands, but I cannot figure out how it really work, the default print is quite annoying, so I cannot figure out in which order the commands are executed.

   sed -e 'command 1' -e 'command 2'  input.txt

input.txt 的内容:

content of input.txt:

line1
line2
line3

问题 1:处理流程是什么?是吗

Question 1: What is the processing flow? is it

command1 processes line1 and then command2 processes new-line1(processed by cmd1)
command1 processes line2 and then command2 processes new-line2(processed by cmd1)
command1 processes line3 and then command2 processes new-line3(processed by cmd1)

command1 processes line1
command1 processes line2
command1 processes line3
command2 processes new-line1(already processed by cmd1)
command2 processes new-line2(already processed by cmd1)
command2 processes new-line3(already processed by cmd1)

问题 2:正如我提到的,默认打印很烦人,我应该在第一个 -e 前面使用 -n 还是在两个 -e 前面使用?

Question 2: As i mentioned, the default print is quite annoying, should I use -n in front of the first -e or in front of both -e?

提前致谢.

编辑(似乎工作流程是第一个假设):

Edit(It seems the working flow is the first assumption):

input.txt

1
2
3

sed -e '{s/1/ONE/;s/2/TWO/;/3/q}' -e '{s/ONE/THREE/}' numbers.txt 

THREE
TWO
3

我试过上面的命令,好像工作流程是command1处理line1,然后command2处理new-line1(cmd1处理它),然后cmd1处理下一行

I tried the above command, and it seems the working flow is command1 processes line1, and then command2 processes new-line1(cmd1 processed it), and then cmd1 processes next line

推荐答案

将 sed -e 命令组合起来创建单个 sed 脚本.以下产生相同的结果(注意 -e 是隐含的):

The sed -e commands are combined to create a single sed script. The following yields the same results (notice that -e is implied):

sed '
    s/1/ONE/
    s/2/TWO/
    /3/q
    s/ONE/THREE/
' input.txt

或者作为单衬:

sed 's/1/ONE/; s/2/TWO/; /3/q; s/ONE/THREE/' input.txt

这篇关于破折号 e(-e) 在 sed 命令中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆