sed - Removing all characters from token to end of line

Hello.
The token is any printable characters between 2 " .
The token is unknown, but we know that it is between 2 "
Tok 1 : "1234x567"
Tok 2 : "A3b6+None"
Tok 3 : "A3b6!1234=@"

The ligne is :
Line 1 :

"9876xABCDE"Do you have any code fragments or data samples in your post

Line 2 :

"nboobd"    Use descriptive thread titles when posting

But it is possible that there is a whitespace at the beginning of the ligne
Line 3 :

        "NFHNEJSniuo112"       See new thread posting rules at the top

Each line is in a file.
And I would like the command like : sed parameter file1 > file2

sed  's/[ |]"[.*]".*/[.*]/g'  file1 > file2

should give

"NFHNEJSniuo112"

in file2
with parameter something like :

's/[ |]"[.*]".*/[.*]/g

with file1 containing something like :

"NFHNEJSniuo112"

See new thread posting rules at the top

Any help is welcome

Think awk may be more appropriate, you can use its token splitting features to extract exactly what you want. Tell it that " splits columns and the token will always be the second column, i.e. $2.

FS is the special variable for column separator, so I'm just printing quote, token, quote.

awk -F"\"" '{ print FS $2 FS }' inputfile > outputfile
1 Like

I agree that awk solution is more readable, but just for the heck of it, here is sed command that should do the trick:

sed 's/.*\("[^"]*"\).*/\1/'
1 Like

Great

But I Known very few with sed and nothing with awk.

Thank you for helping.

---------- Post updated at 18:42 ---------- Previous update was at 18:40 ----------

Great

Thank you for helping.