I am new to the command prompt want to know how all the command works …
I want to know how to apply pipe and filter in cmd to go through the directory and print only those files/folders that were created on a particular date, and want to use a data that occurs 2 -3 times within the files and folders of your test directory.
Go to Start>Help and support enter command prompt in the box and press the magnifying glass symbol at the end. Then select Command Reference Overview [H1S] from the list displayed. This will show the commands available.
Obviously, there are other articles that may be of aid as other selections.
Generally, typing
commandname /?
from the prompt will show (often cryptic) help
Essentially, the pipe symbol, | is used to direct the output of one command to the input of a second, so
dir | sort
for instance takes the screen-output of the DIR command and SORTs it.
The next question uses the critical term created. Each file may have THREE different times, the time the file was created, the time the file was last written to and the time the file was last accessed. It's possible to access all three times, but the default is the time last written. This is the normal time reported by DIR, and can variously be referred to as the file time or the update time amongst other terms.
Hence, to list the files (using the common written date) and select on a particular date, try
dir | find "dateyourequire"
where you need to replace dateyourequire with the target date, in the format matching that displayed by your DIR command. BTW commands are NOT case-sensitive - with one important exception.
Now date-format is a whole new ballgame, and you need to be very careful because the date shown is according to local convention. Some people use DD/MM/YY for instance - others use MM-DD-YY and there are many others. If you are discussing date and time, you need to say EVERY TIME the convention you are using.
You need to explain what you mean by your data that occurs 2 -3 times point. I can make neither head nor tail of it. Examples are usually a good way.
<your_command> | findstr "search_string*"
you can use parameter like /I /B etc. you can also use Regular expression for more information about findstr please see the reference help findstr
Related
I tried to give a sample of a list of my titles. Here it is:
'197. Module Introduction.txt' '198. Our Starting Setup.txt' "199. What's So Complex About Forms.txt" '200. Dealing With Form Submission & Getting User Input Values.txt' '201. Adding Basic Validation.txt' '202. Providing Validation Feedback.txt' '203. Handling the "was touched" State.txt' '204. React To Lost Focus.txt' '205. Refactoring & Deriving States.txt' '206. Managing The Overall Form Validity.txt' 'Assignment 5: Time to Practice: Forms.txt' '207. Adding A Custom Input Hook.txt' '208. Re-Using The Custom Hook.txt' '209. A Challenge For You.txt' '210. Applying Our Hook & Knowledge To A New Form.txt' '211. Summary.txt' '212. Bonus: Using useReducer.txt' '213. Module Resources'.txt
All those titles were in a text file named lectures.txt.
I wanted to create a series of titled blank text files in a folder I had already created to receive them. Each text file should have the specific titles as in that example list. Ultimately I would be creating nearly 500 files, but all of them would have very specific meaningful titles.
I tried to follow all the instructions I found on this forum and elsewhere, on a very long search for help. None of them directly addressed my problem.
They all gave answers for creating multiple files with meaningless names. I don't see the utility in creating a bunch of files named 1.txt, etc, or a.txt, or some combination with a leading standard meaningless lead like filename, or sample...
I may be wrong about that lack of usefulness, but at the very least, it's not what I tried to ask and get an answer for.
I already have the meaningful filenames I want, a lot of them. I want to create many empty text files with names that I already have.
The only remotely useful suggestion (for me) that I got was using touch from a linux or bash prompt.
I found that if I wrapped my titles in quotations and separated the titles by a single space I could get the touch command to kind of work. I also discovered that my file titles could not contain any forward slashes ("/"). Nobody explained to me that the titles had to be wrapped in quotes. I figured that out quickly. Nobody told me how to separate the filenames. I experimented until I found a separation that worked.
I tried some experimenting with the {} bracing and the touch command but wound up not being able to figure out how that could help me in my particular case.
Also, I don't know if it has to do with a buffer on the bash or in PowerShell (I tried using both the Git installation in Windows 10 and bash from PowerShell 7.2.1, but I found that only about seven titles in the list would be touched. The rest resulted in a command not found error.
I broke up the list into about seven titles each and ran touch on each of those filenames (my titles) list segments. That way, on that very list sample I display above from my lectures.txt file, I got my empty text files created successfully, even though I had to do it in three touch commands.
I may have confused some of the people who tried to help me by putting all the titles in a text file that I named lectures.txt.
The contents of that file were the titles I wanted for my text files. Thank you so much those who did reach out to me.
I had already found something that might work in bash but I couldn't get it to work. It was roughly on the line of
`touch prefix{1..3}.txt`
This had the same problem that all the other command suggestions I found had as well, like
echo > filename.extension
The same for the apparently most popular
for /l %a in (1 1 10) do type nul > "%a.txt"
which created ten files named 1.txt through 10.txt. That was not the least bit useful to me.
I know my question got voted down as being exceptionally bad, but I'm editing and adding what I found out, so maybe sort of answering my own question.
If you are looking to do what I'm trying to do, and not just create meaningless filenames, I hope you will find some of what I did helpful. Here's a list of suggested solutions of which NONE did I find useful.
https://techpp.com/2021/08/22/create-file-using...
https://www.quora.com/Can-you-create-multiple-f...
https://www.howtogeek.com/725207/how-to-create-...
How to create multiple empty files on cmd(Windows).
Create multiple files with Powershell?.
https://www.laptopmag.com/how-to/create-multipl...
Remember that using space in bash is not recommended, but if you need to...
You can try something like that:
counter=1
for title in $(cat lectures.txt)
do
touch "$counter - $title.txt"
counter=$((counter+1))
done
EDIT
I only added the title on lectures.txt
NEW EDIT
If lectures.txt has 1 title per line you can do this:
while IFS= read -r line || [ -n "$line" ]
do
touch "$line"
done < lectures.txt
Get-Content -Path '.\lectures.txt' | ForEach-Object { New-Item -Path ".\$($_)" }
or using aliases it's: gc '.\titles.txt' | % { ni ".\$($_)" }
from a powershell console at the required folder and enter the command.
I am currently working on a batch file to note several informations about the computer and now I've got another obstacle which I would like to remove.
As some of you might know it, some of the wmic commands output is rather big and you need to can choose which column you want to see, but for some of those commands it's still pretty much filled with a lot of informations which keep filling up the files.
I've seen there is the command for but I haven't really got a clue how it works exactly because I would like to sort some of the lines to be excluded from the output. Let's take the command wmic nicconfig for example. I only need to informations of the currently used network adapters which are normally just the LAN port and wifi, which at least recieve an IP-Address and/or have a MAC Address which I need to write down.
My question is: Is it possible to explude every line which contains specific word in the description, "Wan Miniport" or "Check Point Virtual Network" f.ex., and/or are Null or empty in MAC Addresses?
Under SQL it would be as simple as just finding the right column name but this isn't sql and therefor I'm stuggling pretty much with this perhaps simple problem.
I just found a possible solution.
It will be something like this:
type C:\TestTextFile.txt | findstr /v Word1 | findstr /v /x Word2 > C:\TestTextFile2.txt
It will just need a little bit more work of defining the rest of the lines which should be excluded. I will try to figure it out with this link.
So I was spliting some large files, everything worked properly until a file of 81GB came to scene. The split command seems that made its job, but the last files has a non correlated name. Look at the right bottom of picture.
And I'm using the command like this:
split -b 125M ./2014.txt 2014/2014_
Anyone knows why instead of create the file 2014_za created the 2014_zaaa?
You can only have 676 files named [a-z][a-z], while your command required more.
Here are some options for what split could do:
Crash.
This is the behavior mandated by POSIX, and followed by macOS.
Start writing larger suffixes.
This is a bad choice because after _zz comes _aaa, but now the files will show up in the wrong order in ls and cat * will no longer join them in correct order.
Save the last range, _z, for longer suffixes.
This is a good choice because after _yz comes _zaaa, which has room to grow while still remaining in alphabetical order. This is what GNU does, and the behavior you're seeing.
If you want all the names to be uniform without triggering any of these behaviors, just use a larger suffix length with -a 6 to ensure you have enough room.
(This is a Windows environment by the way.)
I'm new to batch scripting and, I'll be honest, I'm struggling.
I've done a lot of googling and spent a lot of time trying to work this out but I'm not getting very far. I thought I'd throw this out to the community to see if anyone was up to the challenge. :)
First up, this is for my own personal use and curious interest to see if this is possible without writing a new .exe in a more... conventional language.
This is it : I'm using some software which is essentially portable. the only downside is that it writes to a .ini file very specific file paths which may not necessarily be correct if using another computer.
For example, if I run the software from a USB in Computer A, that computer might see the USB drive as D: and save a path in the ini as Path=D:\portables\soft1\saves\file1.xyz. But if I later use the same USB in Computer B which assigns a different letter to the drive (let's say E:) then the software will throw its toys out of the pram, because it's looking on the wrong drive for what should be now on E:. And if I run the software from a network drive or even cloud storage then the path's get even more complex.
I want to run a script that might, before running the software's .exe, look in the .ini for all instances of such filepaths and replace the full path with simply Path=.\saves\file1.xyz. The software is happy with this and can find what it needs to.
This is the ONLY thing that prevents the software being portable.
This is how I thought it would be done...
Search each line in the .ini, one at a time, to see if contains the
substring "Path="
If it finds it do the following...
a. Store the position of the character AFTER the "=" in "Path=" in a variable (let's say it's vPosA=6)
b. Search the same line for another substring "\saves\" and if it finds that then store the position of the character BEFORE the first "\" in another variable (let's say vPosB=18).
c. If vPosA and vPosB are both >0 then do the following
i. Replace all the characters on that line, from vPosA to vPosB, to "."
ii. Reset vPosA and vPosB both back to "0"
Go to the next line and repeat the process until the end of file is reached, then overwrite the .ini with the changes.
I'm looking forward to seeing what people come up with. Like I said, it's curiosity driving this. If I get no answer, or it's way way too complex I may just write the thing in VB or something and use a .bat to run it before running the software. The advantage of having it as a Batch Script is that it could shared with the software's community and the script is plain to see for all. With a compiled .exe people won't be able to see what's in it and would therefore, justifiably, distrust it.
This should do:
#echo off
setlocal enabledelayedexpansion
(for /f "tokens=*" %%a in (in.txt) do (
set "line=%%a"
if /i "!line:~0,5!"=="Path=" set "line=Path=!line:*\saves=.\saves!"
echo !line!
))>out.txt
type out.txt
Read every line, check if the first five characters are Path= (ignoring capitalization), if yes replace all from start to (including) "\saves" with ".\saves, append the string Path= in front of it. Print the line. Redirect the whole thing to another file.
You can then delete the original file and rename the new file to the old name.
NOTE: this ignores empty lines. It's possible to keep them with some more code.
So I was wondering if it was possible to write something up in the syntax which tells the program to run certain command lines. I'm not very good at explaining, so here's an example:
*Total sample frequency.
FREQUENCIES VARIABLES=Age Gender CigDay CO Min_last Day_abs Cigs_Monthly
/ORDER=ANALYSIS.
*6. Next, using the split-file function, perform the frequency analysis for each gender.
* Split file.
SORT CASES BY Gender.
SPLIT FILE LAYERED BY Gender.
*7 Run frequency again.
FREQUENCIES VARIABLES=Age Gender CigDay CO Min_last Day_abs Cigs_Monthly
/ORDER=ANALYSIS.
So, I was wondering whether it was possible to not have to copy/paste the Frequency command and simply include a line of command that told SPSS to re-run the syntax rows 37 to 38 (Which is where the first frequency command written).
A short answer is - no. There is not a command available that would allow to run a specific line of syntax. Certainly you can do it manually by selecting and running the lines you need.
But there are other options available for such tasks when you need to re-run a part of the code several time:
Insert command. Save the code you need to run several time in an external syntax file and insert it when needed in your main syntax file.
Define and End Define commands. Define the code you need to run several time as a macro command and call it when needed in your main syntax file.
I suggest not using INCLUDE as it is obsolete, although it is still supported. INSERT provides better functionality.
If you set out to build a macro library for your frequently used commands, think about parameterizing them so that, for example, you can pass in the specific variables to use as arguments. See the Command Syntax Reference entry for DEFINE via the Help menu for full details, but be prepared to spend some time studying it.