Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am trying to make a batch file that asks questions then uses the variables to make a html file. Is there a way to replace characters WITHIN COMMAND LINE with the stored variables?
I am making my batch file have a very short HTML template with the basics (font-size, colour) and I want the user to be able to choose the font size and colour then have the batch file output the completed template as a HTML. Heres a bit of my bat file. How do I replace the %%% in a cmd environment?
<html><body>
Hello
</span>NAME HERE
<p <span style='font-size:%%%pt'>
<span style='color:%%%'>
</span></p></body></html>"
You have to escape all <> with a caret in a batch, otherwise this is trivial and should be no problem - even for beginners.
:: Q:\Test\2018\05\08\SO_50222677.cmd
#Echo off&SetLocal
Set /P "_FileName=FileName :"
Set /P "_Size=Size in pt:"
Set /P "_Color=html color:"
Set /p "_Name=Hello name:"
( Echo:^<html^>^<body^>
Echo:Hello
Echo:^</span^>%_NAME%
Echo:
Echo:^<p ^<span style='font-size:%_Size%pt'^>
Echo:
Echo:^<span style='color:%_Color%'^>
Echo:
Echo:^</span^>^</p^>^</body^>^</html^>"
) > "%_FileName%"
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I would like to give me your advice about using cadence orcad
so I can run sequentially cir or net(netlist) files with pspice.exe in cmd of my pc.
I use tcl/tk language.I have tried a few things without any results.
I want to make something similar to this one:
set top {C:\Users\file1.net C:\Users\file2.net};
foreach a $top
{exec D:\\tools\\bin\\pspice.exe -r $a}
There are two problems in your code.
The first problem is that \f is an escape character sequence in lists (for “go down one line”, IIRC; point is you don't want that interpretation). The second problem is that you've got your brace placement wrong in your foreach.
The first problem is best addressed by using / instead of \, and then using file nativename on the value fed to the OS. (You have to do that manually for argument to executables in expr; Tcl can't fix that for you entirely automatically.) The second problem is just a syntax error.
Try this:
set top {C:/Users/file1.net C:/Users/file2.net}
set pspice D:/tools/bin/pspice.exe
foreach a $top {
# Tcl knows how to convert executable names for you; not the other args though
exec $pspice -r [file nativename $a]
}
On Windows you may also try:
package require twapi
set top {C:/Users/file1.net C:/Users/file2.net}
foreach a $top {
twapi::shell_execute -path [file nativename $a]
}
This will work only if *.net files are already associated with PSpice application.
The code above rely on TWAPI extension (if you have it) and its shell_execute function, to open a document just like double-click works.
It's always a good idea to avoid backslashes in your code (no need to put it twice to escape them), file nativename will do the job for you.
Source: https://twapi.magicsplat.com/v4.5/shell.html#shell_execute
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I downloaded a 203775480 bytes (~200 MiB, exact size is important for a later error) JSON file which has all entries all on one line. Needless to say, my text editor (ViM) cannot efficiently navigate in it and I'm not able to understand anything from it. I'd like to prettify it. I tried to use cat file.json | jq '.', jq '.' file.json, cat file.json | python -m json.tool but none worked. The former two commands print nothing on stdout while the latter says Expecting object: line 1 column 203775480 (char 203775479).
I guess it's broken somewhere near the end, but of course I cannot understand where as I cannot even navigate it.
Have you got some other idea for prettifying it? (I've also tried gg=G in ViM: it did not work).
I found that the file was indeed broken: I accidentally noticed a ']' at the beginning of the file so I struggled to go to the end of the file and added a ']' at the end (it took me maybe 5 minutes).
Then I've rerun cat file.json | python -m json.tool and it worked like a charm.
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 5 years ago.
Improve this question
I have to store data containing tabulations in a file. I would like to use .TSV files (Tab-Separated File).
Here is an example of data (I manually escaped tabs and carriage return for the example):
Computation Display
0 for (int i=0;i<10;i++)\n\tx*=3; printf ("<b>éàè'"</b>");
1 float pi=3.1415; printf("%d %f",x,xf);
Is there a proper way to escape tabs? Should I use \t, should I use quotes or double quotes?
The abbreviation CSV means "Comma Separated Values", but in practice, this abbreviation is used for all files containing values that are separated by some separator-character. That's why spreadsheet applications like Open Office Calc or Microsoft Excel open up a dialog window letting you configure the separator and quoting character when you attempt to open a file with the file-extension .csv.
If your question is how the separator-character can be part of a value of a CSV file, the most common way is quoting the values. Here is in example of the quoting being done with the values
a,b
c"d
e
with , as the separator character and " as the quoting character
"a,b","c""d", e
The second way of quoting is the way Excel does it, you can also see variants where the quoting is done in the same way as the first example.
There are libraries out there that do the parsing and creation of CSV files for you. We "here" use the Ostermiller CSV library (there might be better ones nowerday but it does its job so there was no need to change the library after we introduced it "here" 10 years ago.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
script.sh:
#!/bin/sh
var1="CAT"
var2="sucks"
table.html:
<html>
<head></head>
<body>
<table>
<tr>
<td> var1 </td>
</tr>
<tr>
<td> var2 </td>
</tr>
</table>
The variables from script are var1 and var2</p>
</body>
</html>
I have script.sh that has 2 variables; var1 and var2. And I have a separate table.html file. Now I want the values of var1 and var2 in the HTML table.
And I want that when the script runs I should get table in the mail.
Here is what you could do:
Use some convention for burying shell variable names in your HTML - say, __shell_var__ instead of just shell_var. This will make it easy to identify the shell variables and prevent any other strings from being replaced.
Run the following code that does the substitution for you in one go:
# assumes shell variables are enclosed between __ and __
perl -lpe 's/__(.+?)__/$ENV{$1}/g' html_file > html_file_transformed
See this related post: Replace a part of a string with a shell variable's expansion
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I'm trying to replace all whitespace in a text file with a \t so that I can load the contents into SQL. The problem that I'm having is that I only want to replace white space before the a string containing a mix of white space and other characters.
Before:
1.5e-61 5.3e-58 132 0.99 # 3 # 398 # -1 # ID=6412_1;partial=11;start_type=Edge;rbs_motif=None;rbs_spacer=None;gc_cont=0.394
After:
1.5e-61\t5.3e-58\t132\t0.99\t# 3 # 398 # -1 # ID=6412_1;partial=11;start_type=Edge;rbs_motif=None;rbs_spacer=None;gc_cont=0.394
I essentially want to keep everything after the # character as a string. Can anybody help please?
Parse, process, compose.
while (<>) {
chomp;
my ($data, $comment) = split(/(?=#)/, $_, 2);
$data =~ s/\s+/\\t/g;
print($data, $comment, "\n");
}