How to disable or delete the new line (CRLF) that is added after a command? - windows

when I try "dir" I get:
02/13/2020 03:29 PM <DIR> Saved Games
02/13/2020 03:29 PM <DIR> Searches
02/16/2020 12:57 PM <DIR> Videos
1 File(s) 0 bytes
16 Dir(s) 21,887,438,848 bytes free
<<<<<<<this new line is what I want to delete or disable
I tried commands like
findstr "." test.txt > output.txt
but they all add that new line at the end.
Thank you
EDIT:
I export "dir /B" to a file > output.txt
I need this because another program uses the list, and the last new line crashes it.
The program that loops through that list is hardcoded, so I need to provide it a list without the blank line.

Related

cmd command seporator broken in Windows 10

This is unrelated to Java, however the error occurs when I try to compile my code.
The semicolon in the command is causing Windows cmd to fail
Example
c:\>cd c:\windows <- no error
c:\>cd c:\windows; <- the semicolon is not being used a command separator but as part of the path
The system cannot find the path specified.
cmd doesn't use semicolon as a command separator. If you want to have two commands on the same line, you need to use & or | (depending on what you're trying to do).
; is used as an argument separator on Windows, but it's not supported by most applications. It has nothing to do with cmd, and cmd isn't supposed to deal with it (applications parse their command lines, not cmd). It also doesn't apply to cmd intrinsics like cd (cd is not an application).
If you have a directory with a semicolon in the name try wrapping it in "double quotes."
Can't exactly verify your problem, but see below.
Z:\[]>dir
Volume in drive Z has no label.
Volume Serial Number is CAC7-078B
Directory of Z:\
11/27/2019 08:53 <DIR> .
11/27/2019 08:53 <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 871243935744 bytes free
Z:\[]>md zz
Z:\[]>md zz;
A subdirectory or file zz already exists.
Z:\[]>md "zz;"
Z:\[]>dir
Volume in drive Z has no label.
Volume Serial Number is CAC7-078B
Directory of Z:\
11/27/2019 08:54 <DIR> .
11/27/2019 08:54 <DIR> ..
11/27/2019 08:54 <DIR> zz
11/27/2019 08:54 <DIR> zz;
0 File(s) 0 bytes
4 Dir(s) 871243935744 bytes free
Z:\[]>cd zz;
Z:\zz;[]>cd ..\zz
Z:\zz[]>cd "..\zz;"
Z:\zz;[]>
The issue has been resolved with the following
Adding -J-Djdk.lang.Process.allowAmbiguousCommands=true to netbeans_default_options= in etc/netbeans.conf
The output from the compile command has not changed, however it now finds the directories???

creating mercurial repo in directory whose name has dollar signs

I am trying to create a mercurial repository in a directory whose name includes dollar signs. This is an equivalent and simplified example of what i get on windows 10 cmd.exe with mercurial 4.1.3 :
C:\test\dir1>hg init
C:\test\dir1>hg status
C:\test\dir1>cd ../dir$$1
C:\test\dir$$1>hg init
C:\test\dir$$1>hg status
abort: repository C:\test\dir$$1 not found!
so i hope this is clear, the only difference seems to be the dollar signs in the second directory name. thanks in advance!
Mercurial seems to treat dollar signs as an environment variable escape:
C:\test>set X=abc
C:\test>echo $X # Not the shell expanding it, that would be %X%.
$X
C:\test>hg init $X
C:\test>dir
Volume in drive C has no label.
Volume Serial Number is CE8B-D448
Directory of C:\test
11/10/2017 09:27 PM <DIR> .
11/10/2017 09:27 PM <DIR> ..
11/10/2017 09:27 PM <DIR> abc
0 File(s) 0 bytes
3 Dir(s) 53,899,231,232 bytes free
Mercurial has expanded $X as an environment variable. Also:
C:\test>hg init dir$$x
C:\test>dir
Volume in drive C has no label.
Volume Serial Number is CE8B-D448
Directory of C:\test
11/10/2017 09:30 PM <DIR> .
11/10/2017 09:30 PM <DIR> ..
11/10/2017 09:30 PM <DIR> dir$x
0 File(s) 0 bytes
3 Dir(s) 53,899,091,968 bytes free
Two dollar signs insert one dollar sign. When you are in a directory named dir$$x, Mercurial is using dir$x for the name. I found a workaround with hg -R. status, but better to avoid dollar signs.
this has been entered as a Mercurial bug : https://bz.mercurial-scm.org/show_bug.cgi?id=5739

Recursively searching a directory without changing directory atimes

I'm checking an alternative to 'find' command in shell scripting so as to eliminate the discrepancy of Accessed date of sub directories.
According to my observation, when find command is executed to list all the files in a directory, the accessed date of sub-directories is getting changed.
I want to post genuine statistics in one of the junk platforms, So I have been looking at some forums and got the alternative with 'ls' command. But that doesn't completely fulfill my request.
Below is the answer given by #ghostdog74.
ls -R %path% | awk '/:$/&&f{s=$0;f=0} /:$/&&!f{sub(/:$/,"");s=$0;f=1;next} NF&&f{ print s"/"$0 }'.
But this finds only the files inside the sub directories. I need all the files and sub-directories' files to be listed.
For example:
bash-3.2# pwd
/Users/manojkapalavai/Desktop/SleepTimeReport
bash-3.2# ls
**6th floor** manoj17 manoj26.txt manoj36 manoj45.txt manoj55 manoj70.txt manoj80 manoj9.txt **test1**
manoj14 manoj23.txt manoj33 manoj42.txt manoj52 manoj61.txt manoj71 manoj80.txt manoj90 **test2**.
The highlighted ones are sub-directories inside "SleepTimeReport" directory and remaining are just files. So, when I execute the above command, I get only the below output.
bash-3.2# ls -R ~/Desktop/SleepTimeReport | awk '/:$/&&f{s=$0;f=0} /:$/&&!f{sub(/:$/,"");s=$0;f=1;next} NF&&f{ print s"/"$0 }'.
~/Desktop/SleepTimeReport/6th floor/Script to increase the Sleep Time.numbers.
~/Desktop/SleepTimeReport/6th floor/Zone1Sleep.pages.
~/Desktop/SleepTimeReport/test1/New_folder.
~/Desktop/SleepTimeReport/test1/manoj.txt.
~/Desktop/SleepTimeReport/test1/sathish.txt.
~/Desktop/SleepTimeReport/test1/vara.txt.
~/Desktop/SleepTimeReport/test1/New_folder/Script to increase the Sleep Time.numbers.
~/Desktop/SleepTimeReport/test1/New_folder/Zone1Sleep.pages.
i.e.; only those files inside sub-directories are listed.
Brief explanation of what issue I'm facing, please see below
Manojs-MacBook-Pro:SleepTimeReport manojkapalavai$ ls -l
total 16
drwxr-xr-x 8 manojkapalavai staff 272 Sep 14 15:07 6th floor
-rwxr-xr-x 1 manojkapalavai staff 59 Nov 13 10:41 AltrFind.sh
-rw-r--r-- 1 manojkapalavai staff 0 Nov 2 15:15 manoj%.txt
-rw-r--r-- 1 manojkapalavai staff 0 Nov 2 18:23 manoj1
When I try finding Created time and Accessed Time of the folder 6th floor before using 'find' command, the below is output.
Manojs-MacBook-Pro:SleepTimeReport manojkapalavai$ stat -f '%N, %SB, %Sa' 6th\ floor/
6th floor/, Sep 13 10:34:55 2017, **Nov 13 11:21:33 2017**
Manojs-MacBook-Pro:SleepTimeReport manojkapalavai$ find /Users/manojkapalavai/Desktop/SleepTimeReport/
/Users/manojkapalavai/Desktop/SleepTimeReport/
/Users/manojkapalavai/Desktop/SleepTimeReport//6th floor
/Users/manojkapalavai/Desktop/SleepTimeReport//6th floor/.DS_Store
/Users/manojkapalavai/Desktop/SleepTimeReport//6th floor/Script to increase the Sleep Time.numbers
/Users/manojkapalavai/Desktop/SleepTimeReport//6th floor/Zone1Sleep.pages
Now, after finding all the files inside a directory, below is the output of atime. you can notice the change
Manojs-MacBook-Pro:SleepTimeReport manojkapalavai$ stat -f '%N, %SB, %Sa' 6th\ floor/
6th floor/, Sep 13 10:34:55 2017, **Nov 13 14:26:03 2017**
All tha I have done is just find the files, and atime of sub-folders inside a folder when we find is getting changed to that current time.
Is there any way to solve this?
ls is the wrong tool for programmatic use. Generally, you should be able to fix your find usage to not have an effect on atimes (actually, it's pretty rare for folks to even have atimes enabled at the filesystem level on modern production systems), but if you really want to avoid it, consider the bash globstar option:
shopt -s globstar
for file in **/*; do
echo "Doing whatever with $file"
done

How to read file names from a txt file in cmd prompt(script) and then combine a subset of the files into a PDF file using the cmd line in windows

I have a text file in the following format:
2014-05-13 03:35 PM 48,841 SUR2-**C01**-00-000-PCE-1001-002.pdf
2014-05-13 03:36 PM 43,599 SUR2-**C01**-00-000-PCE-1002-001.pdf
2014-05-13 03:35 PM 51,900 SUR2-**C02**-00-000-PCE-1000-001.pdf
2014-05-13 03:35 PM 53,622 SUR2-**C02**-00-000-PCE-1000-002.pdf
2014-05-13 03:35 PM 52,145 SUR2-**C02**-00-000-PCE-1000-003.pdf
2014-05-13 03:35 PM 50,426 SUR2-**C02**-00-000-PCE-1000-004.pdf
I need to parse this file, and pull out files that match C01 or C02, and send these files to a combined PDF file, one for C01 and one for C02.
How can i parse the file, and string match the file names on C01 or C02?
Then, how can i take the above parse result, and using the file names found, combine them into a PDF from the command line or in script?
merge-C01.bat
1.use awk to parse the file to array
set LIST=($(awk '/C01/{print $5}' file.txt))
2.use pdf merge tool (pdftk) to merge files in array
for %%i in %LIST% do pdftk out.pdf %%i cat output out.pdf

Code to determine target of remote junction

Windows 7/NTFS and later has both symbolic links and junctions, and they are subtly different. (See this excellent set of posts). For logging (and debugging) purposes, I need to be able to resolve the target of a junction on a remote file server. There have been some posts on this topic, but they apply to resolving a junction as the local machine see it.
On \\FileServer, we have a directory G:\Shared that is shared out as PublicShare, so it apears on the network as \\FileServer\PublicShare. Within that directory are sub-directories G:\Shared\SubDir1 and G:\Shared\SubDir2. Also within that directory is a junction G:\Shared\Junc that points to either G:\Shared\SubDir1 or G:\Shared\SubDir2. (The target can change.) Thus, on \\FileServer, one sees
\\FileServer\PublicShare\SubDir1
\\FileServer\PublicShare\SubDir2
\\FileServer\PublicShare\Junc
On a client machine where \\FileServer\PublicShare is mounted (mapped in Windows lingo) as M:\, one thus sees M:\SubDir1, M:\SubDir2, M:\Junc. If, on that client machine, you open a console (cmd.exe) and do dir M:\, Windows gives a nice listing which shows that M:\Junc is a junction and includes the target, G:\Shared\SubDirX, of the junction.
M:\>dir
Volume in drive M is XXXXXXXXX
Volume Serial Number is XXXX-XXXX
Directory of M:\
09/05/2014 07:30 PM <DIR> .
09/05/2014 07:30 PM <DIR> ..
09/05/2014 01:36 PM <JUNCTION> Junc [G:\Shared\SubDir1]
09/06/2014 12:55 PM <DIR> SubDir1
09/05/2014 05:15 PM <DIR> SubDir2
0 File(s) 0 bytes
3 Dir(s) 1,895,493,492,736 bytes free
M:\>
Thus, the target of such a junction is clearly available to a client. Does anyone know how to obtain this information programatically, e.g. which system api to call??? Thanks.
This does the trick:
fsutil reparsepoint query "M:\Junc"
and it seems very reliable.
If you don't want to parse the output of C:\Windows\System32\fsutil.exe, you could simply use DIR:
for /f "usebackq delims=[] tokens=2" %i in ( `dir M:\^|findstr JUNCTION` ) do set RES=%i
Notes:
M:\: you need to display the subfolders (and junctions) of the parent folder of the JUNCTION (in this case: M:\)
findstr: if you have several junctions and want to resolve a specific one, add a |findstr foldername to isolate the right line,
delims=[]: that will divide the output 09/05/2014 01:36 PM <JUNCTION> Junc [G:\Shared\SubDir1] into 3 tokens:
09/05/2014 01:36 PM <JUNCTION> Junc
G:\Shared\SubDir1
"<empty>"
tokens=2: only the second token ("G:\Shared\SubDir1") is of interest
%i: if you run that command in a .bat script, double the '%': %%i in and res=%%i

Resources