Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.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
Linux 当管道输送多行时,如何删除单行中的重复字_Linux_Bash_Unix_Awk_Xargs - Fatal编程技术网

Linux 当管道输送多行时,如何删除单行中的重复字

Linux 当管道输送多行时,如何删除单行中的重复字,linux,bash,unix,awk,xargs,Linux,Bash,Unix,Awk,Xargs,现在,我正在通过命令xargs-n1 | sort-u | xargs(我在这里找到了:)输送一些行 但是,我的问题是,当输送多条管线时,它会将所有管线放在一起。我如何通过管道: My first example line for example My second example line for example My third example line for example 并获得: My first example line for My second example line fo

现在,我正在通过命令
xargs-n1 | sort-u | xargs
(我在这里找到了:)输送一些行

但是,我的问题是,当输送多条管线时,它会将所有管线放在一起。我如何通过管道:

My first example line for example
My second example line for example
My third example line for example
并获得:

My first example line for
My second example line for
My third example line for
因为在此之前我运行了很多管道,并且它将在一个循环中运行,所以我更希望您知道任何简单的解决方案,而不必创建新的循环并逐行阅读。我只想让它一次工作一行,这样我就可以把它直接放到循环中。感谢您的考虑。

$awk'{delete seen;c=0;对于(i=1;i1?OFS:),$i;print'}文件
$ awk '{delete seen; c=0; for (i=1;i<=NF;i++) if (!seen[$i]++) printf "%s%s", (++c>1?OFS:""), $i; print ""}' file
My first example line for
My second example line for
My third example line for
我的第一行示例 我的第二行示例 我的第三行示例
稍微简单一点
awk
程序,但不保留顺序(您的管道都不保留顺序,因此我假设这不是您的要求):

$awk'{删除a;for(i=1;i)
$ awk '{delete a; for(i=1;i<=NF;i++) a[$i]; for(w in a) printf w" ";print ""}' lines 
first line My for example 
line My for second example 
line My third for example