bash, extract string before a colon

user788171 picture user788171 · Dec 3, 2013 · Viewed 94.6k times · Source

If I have a file with rows like this

/some/random/file.csv:some string
/some/random/file2.csv:some string2

Is there some way to get a file that only has the first part before the colon, e.g.


I would prefer to just use a bash one liner, but perl or python is also ok.


ray picture ray · Dec 3, 2013
cut -d: -f1


awk -F: '{print $1}'


sed 's/:.*//'