I'm trying to make a HTML file with command line, but there is one problem. I need the quotes otherwise the echo doesn't work. But now the quotes are also displayed on the HTML page. This is my code:
FindStr "BUILD SUCCESSFUL" test1.txt
echo "<html><body><table><tr><td>Plugin</td><td>Resultaten</td></tr>" > goedje.html
if %ERRORLEVEL% ==1 (echo "<tr BGCOLOR="#FF0000"><td>Build</td><td>Fout!</td></tr>" >> goedje.html ) else (echo "<tr BGCOLOR="#00FF00"><td>Build</td><td>Gelukt!</td></tr>" >> goedje.html)
echo "</table></body></html>" >> goedje.html
If i'm doing it without the quotes then the program doesn't run!
In windows, you can use ^ to escape < and >
C:\> echo ^<html^>...^</html^> > result.html
I quess this can be caused by the shell you are using. Your command works for me. You can try using ' ' quotes instead of " " ones.
Basically what you need to do is to skip the special characters in the shell..
For eg : if you want to print " you should use \"
Like that so many characters need to be skipped using some special sequences
check this link for such details
http://www.grymoire.com/Unix/Quote.html
Hope this will help you..
You can also refer
http://steve-parker.org/sh/escape.shtml
Try this code
FindStr "BUILD SUCCESSFUL" test1.txt
echo "<html><body><table><tr><td>Plugin</td><td>Resultaten</td></tr>" > goedje.html
if %ERRORLEVEL% ==1 (echo "<tr BGCOLOR=\"#FF0000\"><td>Build</td><td>Fout\!</td></tr>" >> goedje.html ) else (echo "<tr BGCOLOR=\"#00FF00\"><td>Build</td><td>Gelukt\!</td></tr>" >> goedje.html)
echo "</table></body></html>" >> goedje.html
Related
First of all I'm trying to obtain a certain property from a KML file. For now, I tried
ogrinfo C:/test.kml -so -al | findstr "Extent"
which was recommended to me and outputs
Extent: (-100.054053, 33.702234) - (-94.647180, 37.125712)
I would require this in the form
-100.054053,-94.647180,33.702234,37.125712 for which I thought to use regex.
I tried the following just to see what it outputted:
ogrinfo C:/test.kml -so -al | findstr "Extent" | findstr /r /c:"-*[0-9]*\.[0-9]*"
but this still outputs
Extent: (-100.054053, 33.702234) - (-94.647180, 37.125712)
I read somewhere that Windows' FINDSTR only outputs the line where it matched and not the regex matches themselves. Is there some other way of doing it?
If I get that working I would save the matches in different variables somehow in a shell script. I'm no expert in shell scripting but I've been looking around and was thinking of doing something like this
#!/bin/bash
for /f "tokens=*" %%a in ('ogrinfo C:/test.kml -so -al ^| findstr "Extent" ^| findstr /r /c:"-*[0-9]*\.[0-9]*"') do (
echo %%a
#do something
)
done >output
but running this causes the shell to immediately disappears and can't even see the error.
Assumptions
You have a kml file with raw data.
You can extract a single line which starts with "Extent: " to get the values you want
Single line => there is only 1 line with that format in the kml file
The format of that line is:
Extent: (NUMBER1, NUMBER2) - (NUMBER3, NUMBER4)
A number can have the following characters: 0 1 2 3 4 5 6 7 8 9 . -
The output you want is:
NUMBER1,NUMBER3,NUMBER2,NUMBER4
Using Linux tools only, you can do this:
#!/bin/bash
#
datafile="data.kml"
# Ensure the data file exists
if [[ ! -f "$datafile" ]]
then
echo "ERROR: the data file does not exist."
exit 1
fi
# Extract the "Extent:" line
dataline=$(grep "Extent: " "$datafile")
# Make sure the line is of a valid format, and assign the number variables
if [[ $dataline =~ "Extent: ("([0-9.-]+)", "([0-9.-]+)") - ("([0-9.-]+)", "([0-9.-]+)")" ]] && number1="${BASH_REMATCH[1]}" && number2="${BASH_REMATCH[2]}" && number3="${BASH_REMATCH[3]}" && number4="${BASH_REMATCH[4]}"
then
echo "-----DEBUG-----"
echo "line==$dataline"
echo "1==$number1"
echo "2==$number2"
echo "3==$number3"
echo "4==$number4"
echo "-- END DEBUG --"
echo ""
echo "$number1,$number3,$number2,$number4"
else
echo "ERROR: there is no \"Extent: \" line in the data file ($datafile)"
fi
Details:
Everything is done in the if line.
=~ matches the left side with the pattern on the right side.
In the regular expression, you can define sections you want to reuse with ( ).
Ex: abcd(1)efgh(2)ijkl. The sections you can reuse are 1 and 2.
So in the if, each number is surrounded by parentheses.
When the =~ is processed, the BASH_REMATCH array is defined with each section.
The "DEBUG" echo statements can be removed or commented out.
If you have more than one "Extent: ..." in the KML file, you can loop on the lines and process each one at a time.
Basically I am trying to check if a certain PostgreSQL DB exists with a batch file from the CMD in Windows. Then output custom results onto a text file within the same location, the text file will contain custom values. But the batch I created keeps giving me this (below), does not create the file and instead outputs this on the cmd:
SET _chk_DB=server
was unexpected at this time.
And I would like to know where I went wrong.
I am a beginner with batch so please do take that into consideration.
SET _chk_DB=server
FOR /F "usebackq" %%S IN (psql.exe -h %_svr% -d %_db% -U %_usr%
-P %_psw%
-Q "set nocount on; select count(*) from dbo.sysdatabases where
[name]='%_dtb%'") DO ( SET _chk_DB=%%S )
IF [%_chk_DB%]==[server]
"1" >> Info.text
else
echo "0" >> Info.txt
IF [%_chk_DB%]==[login]
"1" >> Info.text
else
echo "0" >> Info.txt
IF [%_chk_DB%]==[0]
"1" >> Info.text
else
echo "0" >> Info.txt
How to print multiple command output in single line batch?
echo stringProp name="HTTPSamper.xml_dat >> abc.jmx && type
abc.txt >> abc.jmx && echo stringProp >> abc.jmx
I want output of these command to be printed on single line in file abc.jmx
Please help me with this.thanks in advance
Ouput
stringProp name="HTTPSamper.xml_dat
stringProp
Try like this way :
#echo off
(
echo stringProp name="HTTPSamper.xml_dat stringProp
)> abc.jmx
::Read Data from abc.jmx
Type abc.jmx
pause
I have a multiple standard text files that follow this format, with varying numbers of lines in each file:
Line1
Line2
Line3
Line4
I want to merge every line into one, with a space in between each set of characters, so the text file would look as such:
Line1 Line2 Line3 Line3
...and so on. This needs to work with any given number of lines, due to the fact that each text file contains a different number of lines. My intention is not to merge the lines in the text files; I want each text file to remain separate. All the solutions I have found online either don't quite fit this or work exclusively with UNIX. I am running Windows 7. This can be done in Powershell, VBS, Batch, a particular program, doesn't matter, it just needs to work with Windows.
Much appreciated!
#ECHO OFF
setlocal
(SET var=)
FOR /f "delims=" %%x IN (list.txt) DO (
CALL SET var=%%var%% %%x
)
SET var=%var:~1%
echo var=%var%=
Where list.txt is the file containing your lines and var is the variable into which you want the lines concatenated.
Using batch:
for /f "usebackqdelims=" %%i in ("infile.txt") do #<nul set /p"=%%i ">>"outfile.txt"
>>"outfile.txt" echo.
Using PowerShell give this a try and see if it's what you want:
$my_file = "C:\file.txt"
$out_file = "C:\out.txt"
(Get-Content -Path $my_file) -join " " | Set-Content -Path $out_file
For the sake of completeness here's another solution in vbscript:
Set fso = CreateObject("Scripting.FileSystemObject")
Set infile = fso.OpenTextFile("C:\infile.txt")
Set outfile = fso.OpenTextFile("C:\outfile.txt", 2, True)
If Not infile.AtEndOfStream Then outfile.Write infile.ReadLine
Do Until infile.AtEndOfStream
outfile.Write " " & infile.ReadLine
Loop
infile.Close
outfile.Close
Install git-scm, cygwin or something else that contains bash, then you can do
cat *.txt | tr "\n" " "
Something like this?
(gc C:\test.txt) -join " "
What I'm doing is: echo put $clientfilepath'client-'$clientversion-'.jar' >> ftp.ftp in a shell file.
Where $clientfilepath is: c:\\workspace\\project\\jack\\prj1\\target\\ and $clientversion is 1.0-snapshot
What I expect in ftp.ftp:
put
c:\\workspace\\project\\jack\\prj1\\target\\client-1.0-snapshot.jar
But what I'm getting is:
put c:\\workspace\\project\\jack\\prj1\\target\\
client-1.0-snapshot
.jar
I'm using double \ so nothing in the filepath should get treated as a special character.
So does anyone know what's happening?
echo put $clientfilepath'client-'$clientversion-'.jar'|tr '\n' '' >> ftp.ftp
You can simplify the quoting:
echo "put ${clientfilepath}client-${clientversion}-.jar" >> ftp.ftp
Try that to see if it helps with your problem. Also try printf instead of echo:
printf 'put %sclient-%s-.jar\n' "$clientfilepath" "$clientversion" >> ftp.ftp