Assuming you want to replace the Q6938433 in the hyperlink with the Q number at the beginning of each line, you can use the following grep command:
cssgrep -o '^Q[0-9]*' file.txt | xargs -I '{}' sed -i 's/Q6938433/{}/g' file.txt
This command will:
- Use grep to extract the Q number at the beginning of each line of the file
file.txt
. - Use xargs to pass each Q number to sed as an argument (
{}
). - Use sed to replace all occurrences of Q6938433 with the Q number at the beginning of each line (
{}
) in the filefile.txt
.
Make sure to replace file.txt
with the actual filename/path of your file. Also note that the -i
flag in sed will edit the file in-place, so make sure to create a backup copy of your file before running this command.
Yes, you can use BBEdit's "Find All" and "Multi-File Search" features to achieve the same result.
Here are the steps to follow:
Open BBEdit and select "Find All" from the "Search" menu.
In the search field, enter the following regular expression:
css^Q[0-9]*
This will match any Q number at the beginning of a line.
Make sure the "grep" option is selected in the search options.
Click on the "Find All" button. This will highlight all the Q numbers in your file(s).
Close the "Find" window.
Select "Multi-File Search" from the "Search" menu.
In the "Find" field, enter the following regular expression:
Q6938433
This will match the Q number you want to replace.
In the "Replace" field, enter the following replacement string:
mathematica\0\E
This will replace the Q number with itself followed by the Escape character (to avoid breaking any hyperlink syntax).
In the "File Filters" section, specify the file(s) you want to search and replace in.
Click on the "Replace All" button to replace all occurrences of Q6938433 with the corresponding Q number at the beginning of each line.
Make sure to test this on a copy of your file(s) before performing the actual search and replace operation, and make sure to back up your files before making any changes.
To find the Q numbers in the format you've described, you can use the following regular expression in BBEdit's "Find All" window:
cssQ[0-9]+(?=\)\s*Hansson)
This regular expression will match any Q number that is followed by ) Hansson
on the same line. Here's a breakdown of how the regular expression works:
Q
- matches the letter Q[0-9]+
- matches one or more digits(?=\)\s*Hansson)
- uses a positive lookahead to match only if the Q number is followed by a closing parenthesis, optional whitespace, and the word "Hansson".
To perform the search and replace operation, follow the same steps as before, but use this regular expression in the "Find" field instead. The replacement string should be the same as before:
mathematica\0\E
This will replace the Q number with itself followed by the Escape character, to avoid breaking any hyperlink syntax. Make sure to test this on a copy of your file(s) before performing the actual search and replace operation, and make sure to back up your files before making any changes.
To find the Q numbers in the format you've described, you can use the following regular expression in BBEdit's "Find All" window:
cssQ[0-9]+(?=\)\s+[A-Z][a-z]+)
This regular expression will match any Q number that is followed by a closing parenthesis, one or more whitespace characters, and a capitalized name, which is assumed to be the surname of a person. Here's a breakdown of how the regular expression works:
Q
- matches the letter Q[0-9]+
- matches one or more digits(?=\)\s+[A-Z][a-z]+)
- uses a positive lookahead to match only if the Q number is followed by a closing parenthesis, one or more whitespace characters, and a capitalized name.
To perform the search and replace operation, follow the same steps as before, but use this regular expression in the "Find" field instead. The replacement string should be the same as before:
mathematica\0\E
This will replace the Q number with itself followed by the Escape character, to avoid breaking any hyperlink syntax. Make sure to test this on a copy of your file(s) before performing the actual search and replace operation, and make sure to back up your files before making any changes.
To match the first Q number that ends with ]
, you can use the following regular expression in BBEdit's "Find All" window:
cssQ[0-9]+(?=])
This regular expression will match any Q number that is followed by ]
. Here's a breakdown of how the regular expression works:
Q
- matches the letter Q[0-9]+
- matches one or more digits(?=])
- uses a positive lookahead to match only if the Q number is followed by]
.
To perform the search and replace operation, follow the same steps as before, but use this regular expression in the "Find" field instead. Since you only want to match the Q number and not replace it with anything, leave the "Replace" field empty. Make sure to test this on a copy of your file(s) before performing the actual search and replace operation, and make sure to back up your files before making any changes.
To replace the matched Q number with https://www.wikidata.org/wiki/Q6938433
(where Q6938433
is the matched Q number), you can use the following replacement string in BBEdit's "Replace All" window:
arduinohttps://www.wikidata.org/wiki/\0
This will replace the matched Q number (\0
) with the complete URL https://www.wikidata.org/wiki/Q6938433
(assuming Q6938433
is the matched Q number). Here's a breakdown of how the replacement string works:
https://www.wikidata.org/wiki/
- specifies the beginning of the URL.\0
- inserts the matched Q number.
Make sure to test this on a copy of your file(s) before performing the actual search and replace operation, and make sure to back up your files before making any changes.
To replace the string "NewQNumber" with the found Q number in the format https://www.wikidata.org/wiki/<foundQnumber>
, you can use the following regular expression in BBEdit's "Find" window:
cssQ[0-9]+
This regular expression will match any Q number. Here's a breakdown of how the regular expression works:
Q
- matches the letter Q[0-9]+
- matches one or more digits
To perform the search and replace operation, follow these steps:
Open BBEdit and select "Replace All" from the "Search" menu.
In the "Find" field, enter the regular expression
Q[0-9]+
.In the "Replace" field, enter the following replacement string:
arduinohttps://www.wikidata.org/wiki/\0
This will replace the matched Q number (
\0
) with the complete URLhttps://www.wikidata.org/wiki/<foundQnumber>
.In the "File Filters" section, specify the file(s) you want to search and replace in.
Click on the "Replace All" button to replace all occurrences of "NewQNumber" with the corresponding Q number in the format
https://www.wikidata.org/wiki/<foundQnumber>
.
Make sure to test this on a copy of your file(s) before performing the actual search and replace operation, and make sure to back up your files before making any changes.
To replace the string "NewQNumber" with the found Q number in the format https://www.wikidata.org/wiki/<foundQnumber>
, you can use the following regular expression in BBEdit's "Find" window:
cssQ[0-9]+
This regular expression will match any Q number. Here's a breakdown of how the regular expression works:
Q
- matches the letter Q[0-9]+
- matches one or more digits
To perform the search and replace operation, follow these steps:
Open BBEdit and select "Replace All" from the "Search" menu.
In the "Find" field, enter the regular expression
Q[0-9]+
.In the "Replace" field, enter the following replacement string:
arduinohttps://www.wikidata.org/wiki/\0
This will replace the matched Q number (
\0
) with the complete URLhttps://www.wikidata.org/wiki/<foundQnumber>
.In the "File Filters" section, specify the file(s) you want to search and replace in.
Click on the "Replace All" button to replace all occurrences of "NewQNumber" with the corresponding Q number in the format
https://www.wikidata.org/wiki/<foundQnumber>
.
Make sure to test this on a copy of your file(s) before performing the actual search and replace operation, and make sure to back up your files before making any changes.
I apologize for the confusion earlier. To replace the string "<foundQnumber>" with the found Q number in the format https://www.wikidata.org/wiki/<foundQnumber>
, you can use the following regular expression in BBEdit's "Find" window:
cssQ[0-9]+
This regular expression will match any Q number. Here's a breakdown of how the regular expression works:
Q
- matches the letter Q[0-9]+
- matches one or more digits
To perform the search and replace operation, follow these steps:
Open BBEdit and select "Replace All" from the "Search" menu.
In the "Find" field, enter the string
<foundQnumber>
.In the "Replace" field, enter the following replacement string:
arduinohttps://www.wikidata.org/wiki/\0
This will replace the string "<foundQnumber>" with the complete URL
https://www.wikidata.org/wiki/<foundQnumber>
, where<foundQnumber>
is the matched Q number.In the "File Filters" section, specify the file(s) you want to search and replace in.
Click on the "Replace All" button to replace all occurrences of "<foundQnumber>" with the corresponding Q number in the format
https://www.wikidata.org/wiki/<foundQnumber>
.
Make sure to test this on a copy of your file(s) before performing the actual search and replace operation, and make sure to back up your files before making any changes.