This looked easy but it's messing with my head.
Convert this
"value:::text:::::othervalue:::::::text"
to this
"value: : :text: : : : :othervalue: : : : : : :text"
SED isn't recursive, so I get this:
$ echo "value:::text:::::othervalue:::::::text" | sed 's/::/: :/g'
> value: ::text: :: ::othervalue: :: :: ::text
Workaround, sed twice
$ echo "value:::text:::::othervalue:::::::text" | sed 's/::/: :/g;s/::/: :/g'
> value: : :text: : : : :othervalue: : : : : : :text
This doesn't look elegant, and it's not intuitive. Is there any command (in sed maybe?) that might do this more cleanly?
Thanks!
Note: I'm looking for readability.
With GNU sed:
echo '"value:::text:::::othervalue:::::::text"' | sed ':a;s/::/: :/g;ta'
Output:
"value: : :text: : : : :othervalue: : : : : : :text"
From sed man page:
t label: If a s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is omitted, branch to end of script.
: label: Label for b and t commands.
Related
The code starts with # as seen :
####################
# STORAGE VARIABLES
####################
#storage_var
func counter() -> (count : felt):
end
I run : starknet-compile ../counter.cairo --output counter_compiled.json --abi counter_abi.json
and the result is:
counter.cairo:7:1: Unexpected character "#"
Why this problem arises ? Is it about the cairo version ?
how to find all the strings which starts with open square bracket and ends with close square bracket in text file.
used below code but getting some unwanted contents also. How to avoid those unwanted contents
Select-String -Path "text.txt" -Pattern '\['
input file:
some conents [hello]
adfhjadf adfjkkf [ghad]
[check] dfgsf sfgfs
required output file
[hello]
[ghad]
[check]
Here, try this:
$string = #'
some conents [hello]
adfhjadf adfjkkf [ghad]
[check] dfgsf sfgfs
'#
([regex]'\[.*?\]').Matches($string)
Note, this will match anything inside the brackets. If you're looking only for English characters you should refine the regex.
Output should look like this:
Groups : {0}
Success : True
Name : 0
Captures : {0}
Index : 13
Length : 7
Value : [hello]
Groups : {0}
Success : True
Name : 0
Captures : {0}
Index : 39
Length : 6
Value : [ghad]
Groups : {0}
Success : True
Name : 0
Captures : {0}
Index : 47
Length : 7
Value : [check]
If you just want to see the matches you can do:
PS /> ([regex]'\[.*?\]').Matches($string).Value
[hello]
[ghad]
[check]
I have a file that has log entries on each line like:
vert.x-worker-thread-5:606-5 [28281755664384/companyOfflineCaEnricherRSS] [oiq.contentdigestion.PipelineProcessorLink] - CertainClassifierPipelineProcessorInternal COMPLETE [75ms]: http://www.cadc.uscourts.gov/recordings/recordings.nsf/uscadcoralarguments.xml
vert.x-worker-thread-6:524-7 [28281755664384/companyWebAndEventWorkerMultiPass][oiq.contentdigestion.PipelineProcessorLink] - CertainClassifierPipelineProcessorInternal COMPLETE [54ms]: http://a1851.g.akamaitech.net/f/1851/2996/24h/cache.xerox.com/downloads/usa/en/c/CEO_Commitment.pdf
Could any one help me in getting the sed command to have the lines processed in to following pattern
companyOfflineCaEnricherRSS : CertainClassifierPipelineProcessorInternal 75
companyWebAndEventWorkerMultiPass : CertainClassifierPipelineProcessorInternal 54
Use this sed command and get you expected output ,
sed -r 's/[^\/]+.([^]]+).*- ([^ ]+)[^[]+.([^a-z]+).*/\1 : \2 \3/' FileName
-r, --regexp-extended
use extended regular expressions in the script.
OutPut :
companyOfflineCaEnricherRSS : CertainClassifierPipelineProcessorInternal 75
companyWebAndEventWorkerMultiPass : CertainClassifierPipelineProcessorInternal 54
sorry for my english! I have problem, faced here with such a problem, give the decision:
line 1:0 required (...)+ loop did not match anything at input < E O F
>
This my file, calc.g
grammar calc;
options {
language = Java;
}
rule: statement+;
statement
: expr NEWLINE
| ID '=' expr NEWLINE
| NEWLINE
;
NEWLINE : '\r'? '\n'
;
expr
: multExpression ('+' multExpression |'-' multExpression)*
;
multExpression
: a1=atom ('*' a2=atom | '/' a2=atom)*
;
atom
: ID
| INT
| '(' expr ')'
;
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
INT : ('1'..'9') ('0'..'9')*
;
this is my main:
ANTLRReaderStream input = new ANTLRReaderStream();
calcLexer lexer = new calcLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
calcParser parser = new calcParser(tokens);
parser.rule();
It looks like your input is empty: the parser immediately encounters the EOF (end-of-file) where it expects at least one statement.
Try something like this:
ANTLRStringStream input = new ANTLRStringStream("2*42\n");
calcLexer lexer = new calcLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
calcParser parser = new calcParser(tokens);
parser.rule();
As 280Z28 mentioned in the comment beneath my answer, you should probably force the parser to consume the entire input by adding EOF at the end of your parser's entry point:
rule: statement+ EOF;
and if you want to allow an empty string to be valid input too, change the + to a *;
rule: statement* EOF;
I didn't test it but think you have to add the default EOF token to your grammar:
rule: statement+ EOF!;
Your parser seems to recognize the whole input but at the end there is an EOF but you did not add the corresponding rule to your grammar.
I am relatively sure this is quite easy to do but my google fu is not running strong
At the moment I am doing:
add-pssnapin windows.serverbackup
get-wbsummary
This returns me:
NextBackupTime : 07/09/2012 12:00:00
NumberOfVersions : 210
LastSuccessfulBackupTime : 06/09/2012 21:00:13
LastSuccessfulBackupTargetPath : \\?\Volume{bf315689-e5ed-11e1-a376-d067e5f384ea}
LastSuccessfulBackupTargetLabel : SBSERVE 2012_08_21 12:20 DISK_01
LastBackupTime : 06/09/2012 21:00:13
LastBackupTarget : SBSERVE 2012_08_21 12:20 DISK_01
DetailedMessage :
LastBackupResultHR : 0
LastBackupResultDetailedHR : 0
CurrentOperationStatus : NoOperationInProgress
What I want to do is get just the result portion (not its title into a variable) so for example $lastbackuptime = 07/09/2012 12:00:00
PS> $wbs = Get-WBSummary
PS> $lastbackuptime = $wbs.NextBackupTime