Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.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 使用awk修改输出_Linux_Bash_Awk - Fatal编程技术网

Linux 使用awk修改输出

Linux 使用awk修改输出,linux,bash,awk,Linux,Bash,Awk,我有一个命令,它给了我输出: /home/konnor/md5sums:ea66574ff0daad6d0406f67e4571ee08 counted-file.xml.20131003-083611 我需要输出为: ea66574ff0daad6d0406f67e4571ee08 counted-file.xml 我得到的最接近的结果是: $ echo /home/konnor/md5sums:ea66574ff0daad6d0406f67e4571ee08 counted-fil

我有一个命令,它给了我输出:

/home/konnor/md5sums:ea66574ff0daad6d0406f67e4571ee08  counted-file.xml.20131003-083611
我需要输出为:

ea66574ff0daad6d0406f67e4571ee08  counted-file.xml
我得到的最接近的结果是:

$ echo /home/konnor/md5sums:ea66574ff0daad6d0406f67e4571ee08  counted-file.xml.20131003-083611 | awk '{ printf "%s", $1 }; END { printf "\n" }'

/home/konnor/md5sums:ea66574ff0daad6d0406f67e4571ee08

我不熟悉awk,但我相信这是我想要使用的命令,有人有什么想法吗?

或者只是一个sed oneliner:

 echo /home/konnor/md5sums:ea66574ff0daad6d0406f67e4571ee08  counted-file.xml.20131003-083611 \
     | sed -E 's/.*:(.*\.xml).*/\1/' 

或者只是一个sed oneliner:

 echo /home/konnor/md5sums:ea66574ff0daad6d0406f67e4571ee08  counted-file.xml.20131003-083611 \
     | sed -E 's/.*:(.*\.xml).*/\1/' 
请注意,这取决于点
是否存在于
counted file.xml


请注意,这取决于点
counted file.xml

中的存在,不确定这是否适合您:

sed 's/^.*:\(.*\)\.[^.]*$/\1/'
以你的例子:

kent$  echo "/home/konnor/md5sums:ea66574ff0daad6d0406f67e4571ee08  counted-file.xml.20131003-083611"|sed 's/^.*:\(.*\)\.[^.]*$/\1/'                                        
ea66574ff0daad6d0406f67e4571ee08  counted-file.xml
grep行也适用:

grep -Po ':\K.*(?=\..*?$)'

不确定这是否适合您:

sed 's/^.*:\(.*\)\.[^.]*$/\1/'
以你的例子:

kent$  echo "/home/konnor/md5sums:ea66574ff0daad6d0406f67e4571ee08  counted-file.xml.20131003-083611"|sed 's/^.*:\(.*\)\.[^.]*$/\1/'                                        
ea66574ff0daad6d0406f67e4571ee08  counted-file.xml
grep行也适用:

grep -Po ':\K.*(?=\..*?$)'

$awk-F[:.]-v OFS=“.”“{print$2,$3}”
$awk-F[:.]-v OFS=“.”“{print$2,$3}”它仍然需要从文件名中删除尾部的
.20131003-083611
。简单的改变<代码>'s/*:(.*\.xml)。*$/\1/'
Oopsie。。。忘了:)兄弟。。。这是我见过的最美的东西。谢谢。它仍然需要从文件名中删除尾随的
.20131003-083611
。简单的改变<代码>'s/*:(.*\.xml)。*$/\1/'
Oopsie。。。忘了:)兄弟。。。这是我见过的最美的东西。非常感谢。