Delete String(s) Between Two Pattern Matches [closed] - regex

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to delete "PK WND 16026/1736" from the below text by removing any text between "RMK A02" and "SLP."
Text
KDFW 151753Z 17018G25KT 10SM FEW035 FEW120 SCT250 32/21 A2983 RMK AO2 PK WND 16026/1736 SLP093 T03220211 10322 20239 58008
Code
sed -e 's/\(RMK A02\).*\(SLP\)/\1\2/'
The above code doesn't appear to be working/deleting "PK WND 16026/1736."

Here is one way to do it:
awk -F"RMK AO2.*SLP" '{$0=$0~FS?$1"RMK AO2 SLP "$2:$0}1' file
KDFW 151753Z 17018G25KT 10SM FEW035 FEW120 SCT250 32/21 A2983 RMK AO2 SLP 093 T03220211 10322 20239 58008

Related

How to use if else comparing string in a batch file? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
I would like to check the string is match or not. I tried this way, but it always return error, syntax error, I don't know which syntax that error.
Error message
The syntax of the command is incorrect.
if TXT EQU TXT(
SET Format=TXT
REM ECHO %Format%
if %Format% EQU TXT(
ECHO Format correct
GOTO END
)
ECHO Format not correct
This works for me:
#echo off
set format=TXT
if "%format%"=="TXT" (
#echo Format correct
goto :end
)
#echo Format not correct
:end

How to compare strings using =~? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
I'm trying to create a string that will verify if input time is in the right format. I keep getting the 'else' portion to execute, but never the 'then' portion. I'm not sure where in the string there is a mistake. I execute the script in the shell using ./. I test it with 01:20. It will give me "Time entered is valid." when I input single digit int values. I want it to recognize the 00:00 format. Any suggestions?
echo "enter time" ; read time
if [[ '^(([01][0-3])|([2][0-9]))[:][0-5][0-9]$' =~ $time ]]
then
echo "Time entered is valid."
else
echo "Time entered is NOT correct."
fi
=~ is not commutative; the string you want to match must go on the left, the regular expression on the right.
if [[ $time =~ '^(([01][0-3])|([2][0-9]))[:][0-5][0-9]$' ]]

Converting rows from one format to another format using linux tools [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
let's consider following format of raws:
| Node[42]{id:42} | Node[208813]{id:208813} | Node[292823]{id:292823} |
Is is possible to use Linux tools to map it into:
42,208813,292823
Where, these numbers are numbers gathered from [].
Please note that I search for universal method for more columns, for example:
| Node[42]{id:42} | Node[208813]{id:208813} | Node[292823]{id:292823} | Node[1]| into
42,208813,292823,1.
Please note also that {id:292823} is optional (it is not mandatory).
Can anyone help?
With sed:
sed 's/[^[]*\[//;s/\][^[]*\[/,/g;s/].*//' file
Output:
42,208813,292823
See: man sed and The Stack Overflow Regular Expressions FAQ

Python3 Regex groupdict not working properly [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Using Python 3.4.3
I'm trying to do a regex to split CSS like identifiers. My pattern is:
pattern = re.compile("(?P<tag>[^.#]+)?(#(?P<iḍ>[^.#]+))?(?P<classes>([.][^.#]+)+)?")
My test string is h2#label. When I do the match, the groups I get are ('h2', '#label', 'label', None, None) which is correct.
If I get the groupdict of the match I get {'classes': None, 'iḍ': 'label', 'tag': 'h2'} which also looks correct. However, when I try to retrieve the value of id I get a result as if it's not present.
Doing "id" in match.groupdict() yields False and doing "match.groupdict().get("id")yieldsNone`.
Any idea what's wrong here and how to solve it?
You need to fix the typo: instead of 'iḍ' type 'id'.
pattern = re.compile("(?P<tag>[^.#]+)?(#(?P<id>[^.#]+))?(?P<classes>([.][^.#]+)+)?")

Removing non-alphabetic characters in VBScript run from command line [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm trying to remove all the non-alphabetic characters in a string in a VBScript that will run from the command line.
Here's what I have thus far:
Set wshShell = CreateObject("WScript.Shell")
Dim test
test = "Hello:, world!"
test = strClean(test)
WScript.Echo(test)
Function strClean(strVal)
Set objRegEx = CreateObject(“VBScript.RegExp”)
objRegEx.Global = True
objRegEx.Pattern = “[^A-Za-z\n\r]”
strSearchString = objRegEx.Replace(strVal, “”)
End Function
But I'm getting the following error:
my.vbs (8, 35) Microsoft VBScript compilation error: Invalid character
The quotes you're using are Unicode and are invalid.
You should replace them by ASCII ones.
This is a community answer from Slai's comment that doesn't want to write an answer.See this meta post for more info.