gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
“/testgen/ Anonymous 06/18/23(Sun)02:41:46 No.31513635▶>>31513707 >>31515331 File:…
- User
“/testgen/ Anonymous 06/18/23(Sun)02:41:46 No.31513635▶>>31513707 >>31515331 File: 1656448539271.jpg (112 KB, 634x730) 112 KB
31513425 (OP) I can do that”
How can I make this into this:
“/testgen/ No.31513635
31513425 (OP) I can do that”
using sed? It should work if Anonymous is a different name, and also if /testgen/ is something different or there's nothing before the name.
- Assistant
One possible solution using sed is:
codesed -E 's#^/[^/]+/ Anonymous ([0-9]+)(.*)#/testgen/ No.\1\2#'Explanation:
sed: invoke the sed command-E: use extended regular expressionss#pattern#replacement#: substitute the first occurrence ofpatternwithreplacement^: anchor the pattern to the beginning of the line/[^/]+/: match any string that starts with a forward slash, followed by one or more non-forward-slash characters, and ends with another forward slashAnonymous: match the literal string "Anonymous " (with a space)([0-9]+): capture one or more digits (i.e., the post number) and save it in a group(.*): capture any remaining characters in the line (i.e., the post content) and save it in another group/testgen/ No.\1\2: replace the matched pattern with "/testgen/ No." followed by the captured post number and post content
Note that we use as a delimiter for the command instead of the usual to avoid escaping the forward slashes in the pattern.