Pipe and Filter
Asked Answered
B

3

22

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.

Baiss answered 24/3, 2013 at 14:7 Comment(1)
Please read this first: Rubber Duck Problem Solving.Phenol
C
24

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.
Chamois answered 24/3, 2013 at 17:48 Comment(1)
Also worth noting, if all you're trying to do is kill some process you could do - C:\>Taskkill /IM firefox.exe /F or C:\>Taskkill /PID 12345 /F The /f kills the process by force. PID is process ID which you could find by doing tasklist and the IM I think is instance multiples (not sure though) - but you can use it to kill all running instances, so go figure!Grub
L
21
<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

Lobectomy answered 27/9, 2018 at 9:40 Comment(0)
Q
1

To use regular expressions, these two examples for tem and me may help.

Given these folders inside C:\tmp\Regex_Test

C:\tmp\Regex_Test>tree
C:.
├───atem
├───atem1
├───tem
├───temA
└───xtemB

List the content of the directory C:\tmp\Regex_Test and filter for every entry that has tem somewhere.

C:\tmp\Regex_Test>dir | findstr /R tem
20.03.2024  10:37    <DIR>          atem
20.03.2024  10:37    <DIR>          atem1
20.03.2024  10:36    <DIR>          tem
20.03.2024  10:36    <DIR>          temA
20.03.2024  10:36    <DIR>          xtemB

Another example, list all entries that contain me and does have at least one character in front and at the end. This will not find a folder named me

C:\Windows>dir | findstr /R .me.
 Volume in Laufwerk C: hat keine Bezeichnung.
 Volumeseriennummer: 861F-B705
07.12.2019  11:14    <DIR>          GameBarPresenceWriter
16.06.2023  23:37    <DIR>          ImmersiveControlPanel
01.10.2023  14:19    <DIR>          SensorFramework
Quarter answered 1/10, 2023 at 13:12 Comment(2)
@Wolf thanks for pointing that out. The updated sample should be a better match.Quarter
We should be aware of some undocumented features and limitations of findstr (especially regarding regex).Andradite

© 2022 - 2024 — McMap. All rights reserved.