如何使用 sed 删除某些单词之间的空白 space?
How to remove blank space between some words using sed?
我想替换一行(多行)中特定单词之间的字符。例如:
first second third | first line
first second third | second line
first second third | third line
first second third | forth line
....
我想替换第三个和 first/second/third/forth 等之间的字符...在 linux.
中使用 sed 或 vi
如果这个问题已经回答了,你能给我提供link吗?
谢谢!
sed -i 's/\ /whatever/g' ej.txt
-i:in file,表示直接在文件中修改
-s: 替换
-'\':识别空白space
-g: 每一行的所有匹配项
您可以使用以下内容:
sed 's/ |.[^a-z]*//g' text.txt
或者如果你想在 'third' 之后有一个 space:
sed 's/ |.[^a-z]*/ /g' text.txt
记住 -i 标志以进行永久更改。
试试这个
sed 's/second third[^a-zA-Z]*/second third/g' file
它将替换第三个和第一个字母之间的所有内容。如果它有效,如果你想修改原始文件,请使用 -i
我想替换一行(多行)中特定单词之间的字符。例如:
first second third | first line
first second third | second line
first second third | third line
first second third | forth line
....
我想替换第三个和 first/second/third/forth 等之间的字符...在 linux.
中使用 sed 或 vi如果这个问题已经回答了,你能给我提供link吗? 谢谢!
sed -i 's/\ /whatever/g' ej.txt
-i:in file,表示直接在文件中修改
-s: 替换
-'\':识别空白space
-g: 每一行的所有匹配项
您可以使用以下内容:
sed 's/ |.[^a-z]*//g' text.txt
或者如果你想在 'third' 之后有一个 space:
sed 's/ |.[^a-z]*/ /g' text.txt
记住 -i 标志以进行永久更改。
试试这个
sed 's/second third[^a-zA-Z]*/second third/g' file
它将替换第三个和第一个字母之间的所有内容。如果它有效,如果你想修改原始文件,请使用 -i