I am trying to replace %lu (0x%lx) with %u (0x%x) for all occurances in a file.
The following command gives "E488: Trailing Characters" Error.
:%s//\%lu (0x/\%lx)//\%u (0x/\%x)/g
Can some one help?
Related
I need some help in TCL. I have the following string as an example:
%3Cdiv%20id%3D%22video-container-direct%22%20style%3D%22position%3A%20relative%3Bpadding-bottom%3A%2056.6%25%3Bpadding-top%3A%2090px
%3Bheight%3A%200%3Boverflow%3A%20hidden%3B%22%3E%3Ciframe%20allowfullscreen%3D%22%22%20frameborder%3D%220%22%20scrolling%3D%E2%80%9Cno
%22%20src%3D%22%2F%2Fwww.vsports.pt%2Fembd%2F68680%2Fm%2F8856%2Fmaisf%2Fce1702fde64b1cf799dded7f1f3ab428%3Fautostart%3Dfalse%22%20
style%3D%22position%3A%20absolute%3Btop%3A0%3Bleft%3A%200%3Bwidth%3A%20100%25%3Bheight%3A%20100%25%3Bborder%3A0%22%3E%3C%2Fiframe
%3E%3C%2Fdiv%3E
and I want to replace everything after % and removing the % of course. I mean, turning %2F to /, %3D to =, and so on.
Easy way is using the uri::urn package from tcllib (Should be installable via your OS's package manager):
#!/usr/bin/env tclsh
package require uri::urn
set s "%3Cdiv%20id%3D%22video-container-direct%22%20style%3D%22position%3A%20relative%3Bpadding-bottom%3A%2056.6%25%3Bpadding-top%3A%2090px
%3Bheight%3A%200%3Boverflow%3A%20hidden%3B%22%3E%3Ciframe%20allowfullscreen%3D%22%22%20frameborder%3D%220%22%20scrolling%3D%E2%80%9Cno
%22%20src%3D%22%2F%2Fwww.vsports.pt%2Fembd%2F68680%2Fm%2F8856%2Fmaisf%2Fce1702fde64b1cf799dded7f1f3ab428%3Fautostart%3Dfalse%22%20
style%3D%22position%3A%20absolute%3Btop%3A0%3Bleft%3A%200%3Bwidth%3A%20100%25%3Bheight%3A%20100%25%3Bborder%3A0%22%3E%3C%2Fiframe
%3E%3C%2Fdiv%3E"
puts [uri::urn::unquote $s]
Tcl 8.7 will let you do it with regsub (URL decoding is even one of the examples, copied below):
# Match one of the sequences in a URL-encoded string that needs
# fixing, converting + to space and %XX to the right character
# (e.g., %7e becomes ~)
set RE {(\+)|%([0-9A-Fa-f]{2})}
# Note that -command uses a command prefix, not a command name
set decoded [regsub -all -command $RE $string {apply {{- p h} {
# + is a special case; handle directly
if {$p eq "+"} {
return " "
}
# convert hex to a char
scan $h %x charNumber
format %c $charNumber
}}}]
puts $decoded
I have to read a string and display it from a stim.txt file. I can read all other fields but not f_string.If you can advice me how to successfully display f_string. I would really appreciate that
stim.txt File extract
0 000aaa 0b0b0b0b " I am here "
I am using
initial
begin
string f_string;
fd = $fopen("stim.txt", "r");
p=$fgets(line,fd);
n_items = $sscanf(line, "%h %h %h %s", cmd, addr, data, f_string);
$display("%h %h %h %s", cmd, addr, data,f_string);
Many thanks
Your problem is that you have quotes that need to be read from your file as well as the string. You will need to read these explicitly, with something like:
n_items = $sscanf(line, "%h %h %h %c %s", cmd, addr, data, DUMMY, f_string);
where %c reads a single character and DUMMY is an 8 bit vector.
The last word in every texts in testing.txt is "< /a>", I echo out the the word and it seems to be no problem, but when I echo out in the for loop, cmd gave me this error : "The system cannot find the file specified."
I know the problem is on the "<" and ">" sign, it stands for redirection, that's how the error created. How am I going to make cmd think I'm working with a string instead of redirection?
#echo off
setlocal EnableDelayedExpansion
set "remove_char=< /a>"
echo !remove_char!
for /f "skip=2 tokens=6*" %%a in (testing.txt) do (
set "string=%%a %%b"
set string=!string:%remove_char%=!
echo !string!
)
pause >nul
If you want to use < and > symbols as variables you have to change them to ^< or ^>
Otherwise they will be treated as Input or Output!
Maybe you can replace this line
set string=!string:%remove_char%=!
with
for %%i in (!remove_char!) do (set string=!string:%%i=!)
I am trying to append strings to a text file. So far, my code looks like this:
echo -%appointment% >>C:\Users\Evan\Desktop\Programming\Events.txt
echo set /a h=(%hours%*3600)+(%minutes%*60) >>C:\Users\Evan\Desktop\Programming\Events.txt
echo set /a i=%day%-%dbf% >>C:\Users\Evan\Desktop\Programming\Events.txt
echo if %g% leq %h% if %b% equ %day% echo %appointment% %time% Today >>C:\Users\Evan\Desktop\Programming\Events.txt
echo if %b% lss %day% if %b% geq %i% echo %appointment% %time% %date% >>C:\Users\Evan\Desktop\Programming\Events.txt
The problem is, the variables %b% and %g% are dependent on the specific occurance. %b% and %g% change with date, so while their values will be accurate when I append them into the text file, their values will NOT be accurate when I actually want to convert the text file into a batch file and use it. How do I literally append the variable %b% as text and not its current value so that it can change every time I run the text file as a batch? If I try to append "%b%" in code with those quotations, in the occuring file, it is simply output as "".
Thank you.
Double the % for the % you wish to output literally.
% escapes % (ie causes it to be interpreted as an ordinary, not a special character.)
^ escapes most awkward characters like | - but not %
I have multiple strings that are in the following format:
"At Revision ###."
Where ### can be one, two, three, or four digits long.
How do I parse that string in cmd to only grab the number?
try this (cmd shell script):
set "string=At Revision ###."
for /f "tokens=3delims=. " %%i in ("%string%") do set "number=%%i"
echo(%number%