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?
- Assistant
One possible solution using sed is:
sed -E 's/^.*No\.[0-9]+/\/testgen\/ No.&/; s/(\s+)File:.*/\1/' input_fileExplanation:
- The first substitution command
s/^.*No\.[0-9]+/\/testgen\/ No.&/matches the beginning of the line^, followed by any characters.*until the patternNo.followed by one or more digits[0-9]+is found. It replaces this pattern with/testgen/ No.followed by the matched digits&. - The second substitution command
s/(\s+)File:.*/\1/matches one or more whitespace characters(\s+), followed by the stringFile:, followed by any characters.*until the end of the line. It replaces this pattern with the matched whitespace\1(to preserve the original indentation) and nothing else (effectively deleting the rest of the line). - The input file is assumed to contain the original text as shown in the example, with one line per record.
Example:
$ cat input_file /testgen/ Anonymous 06/18/23(Sun)02:41:46 No.31513635▶>>31513707 >>31515331 File: 1656448539271.jpg (112 KB, 634x730) 112 KB $ sed -E 's/^.*No\.[0-9]+/\/testgen\/ No.&/; s/(\s+)File:.*/\1/' input_file /testgen/ No.31513635 >>31513425 (OP) I can do that - The first substitution command