sed - delete all characters before dash
awk, bash, sed
Solution
Using awk you can do:
awk 'BEGIN{FS=OFS="- "} NF>1{$1="";sub(/^- */, "")}'1 inFIle
Live Demo: http://ideone.com/2tBU4v
Problem
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 ``` I've been playing around with sed for hours with no avail. I found that `sed 's/ - .*//'` removes all characters after the first instance of `-` but I cannot find the same for before.