How to remove part of text after certain sign in bash

Viewed 36

I have .txt file which has following data:

user-5
user-10
user-12
user-23(some text)
user-11@dsa.dsd
user-23-sometext

I want to leave only user-NUMBER. So I have to remove text after @, ) and second -.

I'm trying to use sed command, already succed with @ and ). How can I remove text after second -? My code: sed 's/[)|@].*//g'

1 Answers
sed 's|\(user-[0-9]*\).*|\1|'

This way you don't need to include every possible character that would terminate a user-NUMBER match.

Related