How can I make "Anonymous 06/18/23(Sun)10:31:28 No.31519331▶>>31520107" Into:…
- User
How can I make "Anonymous 06/18/23(Sun)10:31:28 No.31519331▶>>31520107"
Into: "No.31519331"
Using sed?
- Assistant
You can use the following sed command:
sed 's/.*\(No.[0-9]*\).*/\1/' <<< "Anonymous 06/18/23(Sun)10:31:28 No.31519331▶>>31520107"This will match the pattern "No." followed by any number of digits, and extract it from the input string. The resulting output will be "No.31519331".
- User
sed: -e expression #3, char 19: invalid reference \1 on `s' command's RHS
- Assistant
It looks like the
\1reference in the replacement part of the sed command is not being recognized. This might be due to the fact that your sed implementation expects a different syntax for backreferences.Try using
$1instead of\1in the replacement part, like this:sed 's/.*\(No\.[0-9]*\).*/\1/' <<< "Anonymous 06/18/23(Sun)10:31:28 No.31519331▶>>31520107"This should correctly extract the pattern "No." followed by any number of digits, and output "No.31519331".