user3351901
user3351901

Reputation: 107

Deleting reoccurring strings contained in every line of a file

I have a file that looks like this:

[hello] - one
[hello] - two
[hello] - three
[hello] - four

I want to delete the '[hello] -' in every line so it will give me

one
two
three
four

Upvotes: 0

Views: 35

Answers (2)

jaypal singh
jaypal singh

Reputation: 77105

I would go with cut, but here are some other options:

With awk:

$ awk -F' *- *' '{ print $NF }' << EOF
> [hello] - one
> [hello] - two
> [hello] - three
> [hello] - four
> EOF
one
two
three
four

With sed:

$ sed 's/^\[hello\] - //' << EOF
> [hello] - one
> [hello] - two
> [hello] - three
> [hello] - four
> EOF
one
two
three
four

Upvotes: 0

pajton
pajton

Reputation: 16226

Try this:

cut <filename> -d" " -f3

Upvotes: 1

Related Questions