I want to add totals from lines in a text file.
My file.txt looks like this:
Totals: 7 passed, 0 failed, 0 skipped
Totals: 10 passed, 0 failed, 0 skipped
Totals: 6 passed, 0 failed, 0 skipped
Totals: 9 passed, 0 failed, 0 skipped
Totals: 4 passed, 0 failed, 1 skipped
Totals: 31 passed, 0 failed, 0 skipped
Totals: 10 passed, 0 failed, 0 skipped
Totals: 4 passed, 0 failed, 0 skipped
Totals: 8 passed, 0 failed, 0 skipped
So when I run sumtotals.bat file.txt then I want something like this:
Passed : XX
Failed : 0
Skipped: X
You can to this:
#echo off
set passed=0
set failed=0
set skipped=0
for /f "tokens=2,4,6 delims= " %%a in (%1) do call :add %%a %%b %%c
echo passed=%passed%
echo failed=%failed%
echo skipped=%skipped%
goto :eof
:add
REM echo %1 %2 %3
set /a passed=%passed%+%1
set /a failed=%failed%+%2
set /a skipped=%skipped%+%3
:eof
result:
C:\temp>sumtotals.bat file.txt
passed=89
failed=0
skipped=1
Related
Is it possible to tell whether a process/thread has the PF_NO_SETAFFINITY flag set? I'm running taskset on a series of process ids and some are throwing errors of the following form:
taskset: failed to set pid 30's affinity: Invalid argument
I believe this is because some processes have PF_NO_SETAFFINITY set (see Answer).
Thank you!
Yes - look at /proc/PID/stat's 'flag' field
<linux/sched.h
#define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_allowed */
Look here for details on using /proc:
http://man7.org/linux/man-pages/man5/proc.5.html
https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk65143
Example:
ps -eaf
www-data 30084 19962 0 07:09 ? 00:00:00 /usr/sbin/apache2 -k start
...
cat /proc/30084/stat
30084 (apache2) S 19962 19962 19962 0 -1 4194624 554 0 3 0 0 0 0 0 20 0 1 0 298837672 509616128 5510 18446744073709551615 1 1 0 0 0 0 0 16781312 201346799 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The flags are 4194624
Q: Do you mind specifying how you'd write a simple script that outputs
true/false based on whether you're allowed to set affinity?
A: I don't feel comfortable providing this without the opportunity to test, but you can try something like this...
flags=$(cut -f 9 -d ' ' /proc/30084/stat)
echo $(($flags & 0x40000000))
I've set up a robocopy script and it functions correctly.
However, within the summary in the log file, the Total Times does not make sense to me as the job runs for about 109 minutes, but total returns 3:39:06?
Can someone explain why this looks wrong.
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : 03 April 2019 20:30:04
Source : G:\Backup\
Dest : \\newserver\Backup\
Files : refresh*
Options : /V /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /Z /PF /MT:1 /R:5 /W:5
------------------------------------------------------------------------------
New File 21.0 g G:\Backup\refresh.bak
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 1 0 0 0 0
Files : 1 1 0 0 0 0
Bytes : 21.019 g 21.019 g 0 0 0 0
Times : 3:39:06 0:54:46 0:00:00 0:54:46
Ended : 03 April 2019 22:19:37
I use robocopy to backup folders and individual files via a batch file. This works fine for all folders and nearly all files, but not for files where the name starts with a "-" (minus sign).
My OS: German Windows 7, 64 Bit. (I don't know if that matters.)
My test batch file does this:
SET fileName=-Test.rar
robocopy "folder 1" "folder 2" "%fileName%"
ECHO Errorlevel: %Errorlevel%
Where %fileName% is quoted because the file name may contain spaces as well.
The result is an ERROR : Invalid Parameter.
-------------------------------------------------------------------------------
ROBOCOPY :: Robustes Dateikopieren für Windows
-------------------------------------------------------------------------------
Gestartet: Wed Nov 21 15:42:47 2018
Quelle - E:\BackupThisFile\folder 1\
Ziel - E:\BackupThisFile\folder 2\
Dateien :
Optionen: /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
FEHLER: Ungültiger Parameter #3 : "-Test.rar"
[...]
Errorlevel: 16
Tested versions of "robocopy.exe":
XP010 (Windows XP?)
XP026 (Windows 2000?)
XP027 Win7 32 Bit
XP027 Win7 64 Bit
It always resulted in the same error message or only the equivalent error code 16.
Tested variation of the command:
Then i have tried different variations of the command. Only 1 change (additional quotes) looked remotely promising:
robocopy "folder 1" "folder 2" \""%fileName%""
But it didn't work either:
-------------------------------------------------------------------------------
ROBOCOPY :: Robustes Dateikopieren für Windows
-------------------------------------------------------------------------------
Gestartet: Wed Nov 21 15:43:00 2018
Quelle : E:\BackupThisFile\folder 1\
Ziel : E:\BackupThisFile\folder 2\
Dateien : "-Test.rar"
Optionen: /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
0 E:\BackupThisFile\folder 1\
------------------------------------------------------------------------------
Insgesamt KopiertÜbersprungenKeine Übereinstimmung FEHLER Extras
Verzeich.: 1 0 1 0 0 0
Dateien: 0 0 0 0 0 0
Bytes: 0 0 0 0 0 0
Zeiten: 0:00:00 0:00:00 0:00:00 0:00:00
Nothing was copied even though the file name parameter was kind of recognized.
I guess that the quotes in the value of the parameter are wrong as well.
Does anyone have an idea?
I am making an app where my levels are stored as grids of numbers in a text file, and when reading them in, I keep getting a trailing newline when there isn't one. The content of the text file being read in is the following (note there is no trailing newline, the last line just ends). Ignore the tick marks, they are there for clarity to mark the beginning and end of the file content.
'1 1 0 0
1 0 0 0
0 0 0 0
0 0 0 0'
My code:
let mypath = Bundle.main.path(forResource:"level1", ofType:nil)!
let content = try! String(contentsOfFile:mypath)
let lines:[String] = content.components(separatedBy:"\n")
print("lines=\(lines)")
print("content = '\(content)'")
Output:
lines=["1 1 0 0", "1 0 0 0", "0 0 0 0", "0 0 0 0", ""]
content = '1 1 0 0
1 0 0 0
0 0 0 0
0 0 0 0
'
As you can see, there is a fifth array element, implying that there were four "\n" strings found in the file, when there were only three. Plus the value of content has an extra newline at the end.
Now if I add a trailing newline to the file such that the file content is (everything between the tick marks):
'1 1 0 0
1 0 0 0
0 0 0 0
0 0 0 0
'
The output becomes:
lines=["1 1 0 0", "1 0 0 0", "0 0 0 0", "0 0 0 0", ""]
content = '1 1 0 0
1 0 0 0
0 0 0 0
0 0 0 0
'
It's the exact same as before!
If I add two trailing newlines, then the output accounts for it, becoming
lines=["1 1 0 0", "1 0 0 0", "0 0 0 0", "0 0 0 0", "", ""]
content = '1 1 0 0
1 0 0 0
0 0 0 0
0 0 0 0
'
Why is this? Is it a bug? Is there any way I can turn this "feature" off? I need to count the number of lines, and this is throwing off everything. I know I can trim off all the extra newlines, but that just seems like a patch to avoid the problem rather than a fix to the problem itself.
I am use the following command to list all users and there pending jobs in LSF:
busers -w all
Example output:
USER/GROUP JL/P MAX NJOBS PEND RUN SSUSP USUSP RSV MPEND
aaaaa - - 0 0 0 0 0 0 200
bbbbb - - 100 50 50 0 0 0 200
ccccc - - 1 0 1 0 0 0 200
I'm looking for a command that will only display the users whose NJOBS value is greater than 0, i.e. those who have actually submitted at least one job.
In the example, that would mean that only the lines for users 'bbbbb' and 'ccccc' should appear.
To check all users jobs the simpler method would be:
bjobs -u all
To check suspended ones just use:
bjobs -u all | grep SUSP