SED - 删除破折号前的所有字符 [英] sed - delete all characters before dash
本文介绍了SED - 删除破折号前的所有字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有,我想的第一个实例之前删除所有的字符的文件名列表 -
。所以下面在之前的名字:列表显示为那些在后:列表
I have list of filenames for which I want to remove all character before the first instance of -
. So the names below in the Before: list appears as those in the After: list.
Before:
Adam James - Welcome Home.txt
Mike & Harry - One Upon - A Time.txt
William-Kent - Prince & The Frog.txt
After:
Welcome Home.txt
One Upon - A Time.txt
Prince & The Frog.txt
我一直在玩SED周围小时无果。
I've been playing around with sed for hours with no avail.
我发现 SED的/ - 。* //
的第一个实例后删除所有字符 -
但我不能找到同样的了。
I found that sed 's/ - .*//'
removes all characters after the first instance of -
but I cannot find the same for before.
推荐答案
用awk可以这样做:
awk 'BEGIN{FS=OFS="- "} NF>1{$1="";sub(/^- */, "")}'1 inFIle
这篇关于SED - 删除破折号前的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文