Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用10+;在Linux中使用sed不分词的字符?_Linux_Unix_Sed - Fatal编程技术网

如何使用10+;在Linux中使用sed不分词的字符?

如何使用10+;在Linux中使用sed不分词的字符?,linux,unix,sed,Linux,Unix,Sed,我想提出一个sed命令,其中每10个字符查找一次最近的空格,并将其替换为“|” 我尝试了sed-E-E的//|/\(*?[0-9a-zA-Z]*\)\{10,\}新的.file,但它显示了错误 输入示例: Hello there! How are you? I am trying to figure this out. 预期产出: Hello there!|How are you?|I am trying|to figure this|out. 这适用于给定的示例: $sed-E's/(.{

我想提出一个sed命令,其中每10个字符查找一次最近的空格,并将其替换为“|”

我尝试了
sed-E-E的//|/\(*?[0-9a-zA-Z]*\)\{10,\}新的.file
,但它显示了错误

输入示例:

Hello there! How are you? I am trying to figure this out.
预期产出:

Hello there!|How are you?|I am trying|to figure this|out.

这适用于给定的示例:

$sed-E's/(.{10}[^]*)/\1 |/g'ip.txt
你好|你好吗?我正在努力想办法。
  • (.{10}[^]*)
    这匹配10个字符,后跟任何非空格字符
  • 然后匹配一个空格
  • \1 |
    放回捕获的部分和一个
    |
    字符
基于此,您可以

  • 通过将空格替换为
    [[:space:]
    和非空格替换为
    [^[:space:]
  • 如果添加
    +
    (POSIX ERE)或
    \{1,\}
    (POSIX BRE),则用管道替换一个或多个空白的任何块
你可以用

sed 's/\(.\{10\}[^[:space:]]*\)[[:space:]]\{1,\}/\1|/g' ip.txt
sed -E 's/(.{10}[^[:space:]]*)[[:space:]]+/\1|/g' ip.txt
见:

#/bin/bash
你好!你好吗?我正试图弄明白这一点。”

sed的/\(.\{10\}[^[:space:]*\)[:space:]\{1,\}/\1 |/g'它的工作方式和我想要的一样,我为此奋斗了一天。非常感谢你!谢谢你编辑这个问题。你有什么错误?
Hello there!|How are you?|I am trying|to figure this|out.
Hello there!|How are you?|I am trying|to figure this|out.