ClearCase command to get latest label of a file? - clearcase

What is the ClearCase windows command to get latest label of a latest version file? I found below command at command in clearcase to get list of all labels applied on an element but it lists all latest labels. How to get last label applied instead of all?
cleartool descr -fmt "%l" myFile

I am able to get last applied label by processing cleartool descr command as mentioned above. Following is the batch file content.
#echo off
#cls
setlocal
SET Command='START "" /B /wait cleartool describe -fmt "%%l\n\n" "filename"'
(FOR /F %%a IN (%Command%) DO (
FOR /F "delims=," %%b in ("%%a") do (
FOR /F "delims=)" %%c in ("%%b") do (
FOR /F "delims=(" %%d in ("%%c") do (
echo %%d
)
)
)
)
)
Output: LABEL5

Building upon my old answer, you will have to process the output of cleartool descr -fmt "%lN" myFile in order to display the date for each label and sort by date.
Using %lN will print one label per line.
cleartool descr -fmt "%lN" myFile | xargs cleartool descr -fmt "%Nd %n" | sort | tail -1
Using %ln will use a date format easily sortable: (Numeric) Date and time in numeric form — yyyymmdd.time.

If you're looking for recently applied labels, try using cleartool lshistory -minor... I applied a bunch of labels to test element and got this:
> [brian#thishost cvsimport]$ cleartool lshist -min -last 6 co.dll
> --11-24T14:27 brian make label "LABEL4" on version "co.dll##/main/2" (LABEL4, LABEL5, LABEL6, LABEL3, LABEL2, ...)
> --11-24T14:26 brian make label "LABEL5" on version "co.dll##/main/2" (LABEL4, LABEL5, LABEL6, LABEL3, LABEL2, ...)
> --11-24T14:26 brian make label "LABEL6" on version "co.dll##/main/2" (LABEL4, LABEL5, LABEL6, LABEL3, LABEL2, ...)
> --11-24T14:26 brian make label "LABEL3" on version "co.dll##/main/2" (LABEL4, LABEL5, LABEL6, LABEL3, LABEL2, ...)
> --11-24T14:26 brian make label "LABEL2" on version "co.dll##/main/2" (LABEL4, LABEL5, LABEL6, LABEL3, LABEL2, ...)
> --11-24T14:26 brian make label "LABEL1" on version "co.dll##/main/2" (LABEL4, LABEL5, LABEL6, LABEL3, LABEL2, ...)
These events only last 2-4 weeks (depending on scrubbing parameters), so be aware that this is a time-limited lookup.

Related

Batch file to capture information from a website

I want to get these informations from this website :
1. Day
2. Month
3. Year
4. Time
https://www.timeanddate.com/worldclock/fullscreen.html?n=37
how can i do this?
The best way would be to save all of them in different variables I would say and probably download the information with curl -o random.txt link
I already tried something like this :
curl -s -o r.txt link
set /p V=<r.txt
set V=%V:~4%
I'm sure there's a way easier and better way...
Try this:
#if (#x)==(#y) #end /***** jscript comment ******
#echo off
cscript //E:JScript //nologo "%~f0" "%~nx0" | findstr /r /e "[0123456789]"
exit /b %errorlevel%
***** end comment *********/
var strURL = "https://www.timeanddate.com/worldclock/fullscreen.html?n=37"
var ieOBJ = new ActiveXObject("InternetExplorer.Application");
ieOBJ.Visible = false
ieOBJ.Navigate2(strURL)
do {
WScript.Sleep(100);
} while (ieOBJ.Busy);
var innerText=ieOBJ.document.body.innerText;
WScript.Echo(innerText);
ieOBJ.Quit()
It should be a file with a .bat extension.
So you're basically asking how to extract specific information from a website. You'll need an HTML-parser like xidel for that:
xidel -s "https://www.timeanddate.com/worldclock/fullscreen.html?n=37"^
-e "tokenize(//div[#id='i_date'])[position() gt 1],//div[#id='i_time']"
28
January
2023
21:53:02
We grab the text-node from <div id=i_date>, convert it to a sequence by "tokenizing" on the white-space and only show item 2, 3 and 4. The text-node from <div id=i_time> we grab as-is.
To export these to a cmd-variable:
FOR /F "delims=" %A IN ('
xidel -s "https://www.timeanddate.com/worldclock/fullscreen.html?n=37"
-e "let $a:=tokenize(//div[#id='i_date']) return ($day:=$a[2],$month:=$a[3],$year:=$a[4]),$time:=//div[#id='i_time']"
--output-format^=cmd
') DO %A
ECHO %day% %month% %year% %time%
28 January 2023 21:53:02

`^&` and `$T` in doskey behave similar but not same

I want to open a file in cmd and edit it in Sublime Text's specific group, so I create a doskey like this
rem version 1, ^&
doskey st="path_to\Sublime Text 3\sublime_text" --command "focus_group { \"group\": $1 }" ^& "path_to\Sublime Text 3\sublime_text" $2
rem version 2, $T
doskey st="path_to\Sublime Text 3\sublime_text" --command "focus_group { \"group\": $1 }" $T "path_to\Sublime Text 3\sublime_text" $2
The command before ^& or $T will focus ST on group $1 you want, command after ^& or $T will open the file $2
Then in cmd
>>> rem version 1, ^&
>>> st 0 test.py & rem press enter
>>>
----------------------------------
>>> rem version 2, $T
>>> st 0 test.py & rem press enter, one more prompt compare version 1
>>>
>>>
Another try
rem alias.bat in C:\Windows\System32, work like alias in linux
doskey lscd1=dir ^& cd ..
doskey lscd2=dir $T cd ..
Result
path1\path2> lscd1
Volume in drive C is OS
Volume Serial Number is DA7D-663C
Directory of path2
11/24/2019 09:45 PM 0 test.py
path1>
---------------------------------
path1\path2> lscd2
Volume in drive C is OS
Volume Serial Number is DA7D-663C
Directory of path2
11/24/2019 09:45 PM 0 test.py
path1\path2>
path1>
The Doc of $T is
$T or $t Separates commands. Use either of these special characters to separate commands when you create macros or type commands on the doskey command line. These special characters are equivalent to using the ampersand (&) on a command line.
I guess ^& is 'escape the ampersand', why these two behave differently?
Interesting, I never noticed the difference before.
When using $T the macro issues each command separately to cmd.exe, each one getting its own prompt. However, the subsequent commands are not echoed to the screen, so it looks kind of odd.
For example:
C:\test>doskey $T=echo command 1 $T echo command 2
C:\test>$T
command 1
C:\test>command 2
C:\test>
When you use ^& doskey treats the entire construct as a single command that is passed to cmd.exe all at once, so you don't get any extra prompts. Note that the ^ is consumed during the definition phase so that only & is stored in the definition, not ^&.
C:\test>doskey amp=echo command 1 ^& echo command 2
C:\test>amp
command 1
command 2
C:\test>
You can get $T output to look like ^& if you add echo off and echo on before and after your main definition
C:\test>doskey $T2=echo off $T echo command 1 $T echo command 2 $T echo on
C:\test>$T2
command 1
command 2
C:\test>
If I were to use doskey macros, then I would prefer to use ^&. But I rarely use them because they have severe limitations:
They do not execute when used within batch scripts
They do not execute when combined with pipes
They do not execute when used with FOR /F %A in ('macro') do ...
They do not execute when combined with any of the concatenation operators &, &&, or ||
UPDATE
When I say that $T causes each command to get its own prompt, that means that each command gets parsed separately. This has a potential advantage in that your macro can set variable var and then later on access the value %var% without having to use delayed expansion. When using ^& all commands are parsed at once, so you can't use %var%.
Here is a silly example showing how you can't use %v% with ^& but you can use %v% with $T
C:\test>set "v="
C:\test>doskey m1=set "v=OK" ^& echo v=%v% - doesn't work with ^^^^^^^& ^& set "v="
C:\test>m1
v=%v% - doesn't work with ^&
C:\test>doskey m2=set "v=OK" $T echo v=%v% - works with $^^T $T set "v="
C:\test>m2
C:\test>v=OK - works with $T
C:\test>
A more practical example would be a macro that executes a command then does something based on the resultant %errorlevel%.

How to get the 'BASE' number with 'svn info' command by 'find' filter in Windows batch file?

I want to get the 'BASE' number by 'svn info' command in Windows batch file as the following batch script:
svn update
for /f "tokens=2" %%i in ('svn info -rBASE^|find "Revision"') do (
#echo %%i
set svn_rev=%%i
)
But I always got the 'HEAD' number of my svn managed project code. So I tried the command directly in console:
>svn info -rBASE
Path: AliceAgent4.0b5856
URL: https://192.168.1.116:3443/svn/ProjectAliceVR/AliceOperationAgent/branches/AliceAgent4.0b5856
Relative URL: ^/AliceOperationAgent/branches/AliceAgent4.0b5856
Repository Root: https://192.168.1.116:3443/svn/ProjectAliceVR
Repository UUID: 794566ed1-6640e-7746-860d-66136dce9e99a
Revision: 5936
Node Kind: directory
Last Changed Author: yuanhui.he
Last Changed Rev: 5933
Last Changed Date: 2019-03-21 15:10:43 +0800 (周四, 21 3月 2019)
The Revision is 5936, other than 5933. Then, I tried the HEAD parameter of svn, it output the same result with BASE:
> svn info -rHEAD
Path: AliceAgent4.0b5856
URL: https://192.168.1.116:3443/svn/ProjectAliceVR/AliceOperationAgent/branches/AliceAgent4.0b5856
Relative URL: ^/AliceOperationAgent/branches/AliceAgent4.0b5856
Repository Root: https://192.168.1.116:3443/svn/ProjectAliceVR
Repository UUID: 794566ed1-6640e-7746-860d-66136dce9e99a
Revision: 5936
Node Kind: directory
Last Changed Author: yuanhui.he
Last Changed Rev: 5933
Last Changed Date: 2019-03-21 15:10:43 +0800 (周四, 21 3月 2019)
EDIT:
I have tried 'svn info -rBASE^|find "Last Changed Rev:"' but it only got a Changed string in the batch script.
So, how can I get the number 5933 in the Last Changed Rev: 5933 line?
Basically, there are two issues in this question:
How to get the COMMITTED number other than the HEAD number.
How to correct the find parameter in a Windows batch file to find the correct result.
Honestly, the question How do you determine the latest SVN revision number rooted in a directory? is not fixed my issue but some body answered my question.
I think anybody find my issue here because they are facing the same questions with me. Omit time for them is always valuable, so I arranged answers here:
A1: change BASE or HEAD to COMMITTED can directly get you wants:
svn update
for /f "tokens=2" %%i in ('svn info -rCOMMITTED^|find "Revision"') do (
#echo %%i
set svn_rev=%%i
)
A2: change the for loop's tokens value to 4, then change the find parameter to Last Changed Rev:. This can correct the action of the for loop to find the correct number. I'm not familiar with windows batch scrip, my fault, #Compo.
svn update
for /f "tokens=4" %%i in ('svn info -rHEAD^|find "Last Changed Rev:"') do (
#echo %%i
set svn_rev=%%i
)
As per my comment,
split the input at the colon
using simulated input per text file
use findstr with it's RegEx features ^ anchor at line begin and multiple search strings
set variable name from start of line (with spaces removed) and
use set /A to remove trailing space from number
(might fail with 08xx/09xx being interpreted as octal)
:: Q:\Test\2019\03\22\SO_55291828.cmd
#Echo off&Setlocal EnableDelayedExpansion
::svn update
Echo svn info -rBASE
for /f "tokens=1-2delims=:" %%i in ('
type svn_info-rBASE ^|findstr "^Last.Changed.Rev ^Revision"
') do (
Set "var=%%i"
set /A "_!var: =!=%%j"
)
Set _
Echo:
Echo svn info -rHEAD
for /f "tokens=1-2delims=:" %%i in ('
type svn_info-rHEAD ^|findstr "^Last.Changed.Rev ^Revision"
') do (
Set "var=%%i"
set /A "_!var: =!=%%j"
)
Set _
Sample output:
> SO_55291828.cmd
svn info -rBASE
_LastChangedRev=5933
_Revision=5936
svn info -rHEAD
_LastChangedRev=5933
_Revision=5936

Not skipping empty lines in batch file

I am trying to replicate a file without the 1st line.
But I can't seem to copy it's contents properly.
This is how I tried:
for /f "tokens=* skip=1" %%i in (input.txt) do (
echo %%i >> "output.txt"
)
When my input.txt have this:
test1
1. test item1
2. test item2
3. test item3
It gives me this:
1. test item1
2. test item2
3. test item3
Expected Output:
1. test item1
2. test item2
3. test item3
How do I achieve this?
#ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
SET "destdir=U:\destdir"
SET "filename1=%sourcedir%\q47067655.txt"
SET "outfile=%destdir%\outfile.txt"
(FOR /f "tokens=1*skip=1delims=:" %%a IN ('findstr /n /r ".*" "%filename1%"') DO ECHO(%%b)>"%outfile%1"
(FOR /f "tokens=1*skip=1delims=]" %%a IN ('find /n /v "" ^<"%filename1%"') DO ECHO(%%b)>"%outfile%2"
(more +1 "%filename1%">"%outfile%3")
GOTO :EOF
You would need to change the setting of sourcedir to suit your circumstances.
You would need to change the settings of sourcedir and destdir to suit your circumstances.
I used a file named q47067655.txt containing your data for my testing.
Produces the files defined as %outfile%*
for /f will skip empty lines, so ensure the lines are not empty by numbering them.
Note that echo(%%a will produce an empty line with empty %%a
Your example output omits the blank line between the skipped line and the next.
There is no way to do this with for /f, the documentation from for /? is quite adamant:
Blank lines are skipped.
For a simple need like this, it can be met with the Windows more program, which can start at an arbitrary line and will not actually page the file if it's redirected (up to a certain size anyway). That means your entire script can be replaced with a single command:
c:\users\paxdiablo> more +2 input.txt >output.txt
c:\users\paxdiablo> type output.txt
1. test item1
2. test item2
3. test item3
For more complex tasks or if your files are bigger than what more can handle without paging, you should probably stop using (the frankly brain-dead) older Windows tools and switch instead to PowerShell.
Or get yourself some decent text processing tools for Windows such as sed or awk (see GnuWin32), after which you can just do something like (for your case, though the script can now be arbitrarily complex):
c:\users\paxdiablo> awk "NR>2{print}" input.txt >output.txt

Command to fetch column information

I have a command incmd version which produces below output
All Rights Reserved.
This Software is protected by U.S. Patent Numbers 5,794,246; 6,014,670; 6,016,50
1; 6,029,178; 6,032,158; 6,035,307; 6,044,374; 6,092,086; 6,208,990; 6,339,775;
6,640,226; 6,789,096; 6,820,077; 6,823,373; 6,850,947; 6,895,471; 7,117,215; 7,1
62,643; 7,254,590; 7,281,001; 7,421,458; 7,496,588; 7,523,121; 7,584,422; 7,720,
842; 7,721,270; and 7,774,791, international Patents and other Patents Pending.
Version: 9.1.0 HotFix2
Build: 1668 - 2011-Sep-02
Command ran successfully.
I want to fetch 9.1.0 out of it. so far using findstr "Version" i only get Version: 9.1.0 HotFix2 Is there a way I can extract column information?
Note: Without using any third party tools.. (anytool that is available by default in windows is fine)
You can use for to tokenize that output:
for /f "tokens=2, delims= " %v in ('incmd version ^| findstr Version') do #set Version=%v
echo %Version%
See help for for a detailed explanation of the command and its options.
Note that if you are using this in a batch file (which I assumed at first, but apparently wasn't the case) you have to double the percent signs in the for variable:
for /f "tokens=2, delims= " %%v in ('incmd version ^| findstr Version') do #set Version=%%v
echo %Version%

Resources