我想在一行(多行)的特定单词之间替换字符。例如:
first second third | first line
first second third | second line
first second third | third line
first second third | forth line
....
我想在linux中替换第三和第一/第二/第三/第四etc...using、sed或vi之间的字符。
如果这个问题已经回答了,你能给我提供链接吗?谢谢!
我正试图在一个目录(Linux)的所有源文件中更新或插入一些注释,如版权头。我的文件不一致,所以其中一些文件已经有了头文件,而其他文件根本没有头文件。我尝试用sed查看前几行并替换。替换我的意思是用最新的文件替换已经有版权头的文件。
sed -e '1,10 s/Copyright/*Copyright*/g' file
但是,如果它没有找到模式,则不会插入。我如何才能做到这一点?
我在注释中提供的示例或者我尝试实际替换/插入的示例是一个多行的典型版权头,如下所示
/*
* Copyright 1234 XXXNAME, XYZPlace
* text text text
在Linux中,我可以使用什么命令将单行文本替换为新的多行文本?我想在一行上查找关键字,然后删除此行,并用多个新行替换它。因此,在下面显示的文本中,我希望搜索包含"keyword“的行,并将整个行替换为3行新文本,如下所示。
例如替换包含关键字的行,
This is Line 1
This is Line 2 that has keyword
This is Line 3
更改为:
This is Line 1
Inserted is new first line
Inserted is new second line
Inserted is new third line
This i
我有一个文件,内容如下:
## this must go ##
## also
this
must go
##
hello world
##and this one
too##
我想删除##之间的所有内容,包括多行,所以只剩下hello world了。
这只移除一行上的部分:
sed -i.bak 's/##.*##//g' myfile
如何移除多行的东西?
P.S . Im在MAC上
我正在尝试将AllowOverride文件中的特定"AllowOverride None“替换为"AllowOverride All”。
如果文件有多行,具有相同的模式,我想我会做一个多行模式来替换它.除非sed可以选择何时替换模式。
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileIn
我需要编辑大量的文件,通过插入一行或多行,或者直接在一个独特的模式下或在它上面。请建议如何在shell中使用sed、awk、perl (或其他任何东西)来做到这一点。谢谢!示例:
some text
lorem ipsum dolor sit amet
more text
我想在lorem ipsum dolor sit amet之后插入consectetur adipiscing elit,这样输出文件将如下所示:
some text
lorem ipsum dolor sit amet
consectetur adipiscing elit
more text
我尝试将这一行拆分为多行,每行包含一个单独的句子:
This is a first sentence. This is a second sentence. Look at this: a third sentence! Where does this ends? I have no Idea, who knows…
我们必须尽可能使用最短的命令。
我试过这个:
sed 's/[.?!]/&\n/g'
但它会在每个新句子后添加一个空格:
This is a first sentence.
This is a second sentence.
Look at this
我有一个日志文件,其结构如下:
YYYY-MM-DD-hh-mm-ssThen这样的记录总是以时间数据开头的,可以有一行或多行,包括空行新记录,在行的开头,新记录的开头是两行新行(比如\n字符),后面是YYYY DD-hh。
示例:
2022-05-05-14.06.15.041968 some data
that can spread to one line
2022-05-05-14.06.16.036412 some data
that can spread to
two lines
2022-05-05-14.06.17.234123 some data
that can spre