What's new

Find two or more strings in an output

balubeto

Member
Member
Hi

In the command prompt in Windows 8.x, the output of the dir command produces a list of all files and directories with their information.

If I wanted to display only the output of only two or three files (including their information), how should I do?

Note: These files, that I should see, have completely different names.

Thanks

Bye
 

My Computer

System One

  • OS
    Windows 8

crawfish

Member
Power User
The Unix way would be to pipe dir's output to grep. You can do this at the Windows command prompt provided you have a suitable search program. PowerShell may have such a feature.
 

My Computer

System One

  • OS
    Windows 8.1 Pro with Media Center

Ztruker

Well-Known Member
VIP Member
Guru
Install Unxtools then you have Grep and most of the other neat Unix/Linux tools.

I use grep and tee fairly often.

Having said the above, I don't think grep will do what you want as it only accepts one "pattern". You can't say "pattern1" or "pattern2".
 

My Computer

System One

  • OS
    Windows 10 Pro X64
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Lenovo IdeaCenter K450
    CPU
    Intel Quad Core i7-4770 @ 3.4Ghz
    Motherboard
    Lenovo
    Memory
    16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
    Graphics Card(s)
    Intel Integrated HD Graphics
    Sound Card
    Realtek HD Audio
    Monitor(s) Displays
    HP h2207
    Screen Resolution
    1680x1050@59Hz
    Hard Drives
    250GB Samsung EVO SATA-3 SSD;
    2TB Seagate ST2000DM001 SATA-2;
    1.5TB Seagate ST3150041AS SATA
    PSU
    500W
    Keyboard
    Wired USB
    Mouse
    Wired USB
    Internet Speed
    3GB Up, 30GB Down
    Browser
    SeaMonkey
    Antivirus
    Windows Defender; MBAM Pro
    Other Info
    UEFI/GPT
    PLDS DVD-RW DH16AERSH

crawfish

Member
Power User
Having said the above, I don't think grep will do what you want as it only accepts one "pattern". You can't say "pattern1" or "pattern2".

I was using "grep" in the generic sense. There are three programs in the grep family, grep, egrep, and fgrep. GNU grep subsumed all three, and the various modes are enabled by program options, though distros arrange that you can still say "egrep" and "fgrep". The egrep variant provides full regexp and is the most versatile, though fgrep is useful for searching on a collection of fixed strings (which egrep can also do).
 

My Computer

System One

  • OS
    Windows 8.1 Pro with Media Center

Ztruker

Well-Known Member
VIP Member
Guru
Any chance you can provide an example of searching for two strings in the output from the dir command?
 

My Computer

System One

  • OS
    Windows 10 Pro X64
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Lenovo IdeaCenter K450
    CPU
    Intel Quad Core i7-4770 @ 3.4Ghz
    Motherboard
    Lenovo
    Memory
    16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
    Graphics Card(s)
    Intel Integrated HD Graphics
    Sound Card
    Realtek HD Audio
    Monitor(s) Displays
    HP h2207
    Screen Resolution
    1680x1050@59Hz
    Hard Drives
    250GB Samsung EVO SATA-3 SSD;
    2TB Seagate ST2000DM001 SATA-2;
    1.5TB Seagate ST3150041AS SATA
    PSU
    500W
    Keyboard
    Wired USB
    Mouse
    Wired USB
    Internet Speed
    3GB Up, 30GB Down
    Browser
    SeaMonkey
    Antivirus
    Windows Defender; MBAM Pro
    Other Info
    UEFI/GPT
    PLDS DVD-RW DH16AERSH

MilesAhead

Eclectician
VIP Member
Pro User
Linux type Find command may work. Or a simple ahk directed at the explicit filenames(if they will always be the same.)
For example

Code:
Loop c:\folder\*.*
{
if %A_LoopFilename% in filenameone,filenametwo,filename3
  do something
}
 

My Computer

System One

  • OS
    Windows 8.0 x64
    Computer type
    Laptop
    System Manufacturer/Model
    Toshiba Satelite C55D-A Laptop
    CPU
    AMD EI 1200
    Memory
    4 gb DDR3
    Graphics Card(s)
    Raedon 340 MB dedicated Ram
    Monitor(s) Displays
    Built in
    Screen Resolution
    1366 x 768
    Hard Drives
    640 GB (spinner) Sata II
    Keyboard
    Built in
    Mouse
    Touch pad

Ztruker

Well-Known Member
VIP Member
Guru
This has to run on Windows. Loop is an unknown command in Windows, even with UnxTools installed.
 

My Computer

System One

  • OS
    Windows 10 Pro X64
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Lenovo IdeaCenter K450
    CPU
    Intel Quad Core i7-4770 @ 3.4Ghz
    Motherboard
    Lenovo
    Memory
    16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
    Graphics Card(s)
    Intel Integrated HD Graphics
    Sound Card
    Realtek HD Audio
    Monitor(s) Displays
    HP h2207
    Screen Resolution
    1680x1050@59Hz
    Hard Drives
    250GB Samsung EVO SATA-3 SSD;
    2TB Seagate ST2000DM001 SATA-2;
    1.5TB Seagate ST3150041AS SATA
    PSU
    500W
    Keyboard
    Wired USB
    Mouse
    Wired USB
    Internet Speed
    3GB Up, 30GB Down
    Browser
    SeaMonkey
    Antivirus
    Windows Defender; MBAM Pro
    Other Info
    UEFI/GPT
    PLDS DVD-RW DH16AERSH

crawfish

Member
Power User
Any chance you can provide an example of searching for two strings in the output from the dir command?

Assuming you have egrep:

Code:
dir | egrep -i "this|that"

If you're not fixated on the command line, programs like Xyplorer support regexp finds, and I suppose you could get by with redirecting dir's output to a text file and searching the contents with Notepad++ or similar.

This has to run on Windows. Loop is an unknown command in Windows, even with UnxTools installed.

He was talking about Autohotkey.
 

My Computer

System One

  • OS
    Windows 8.1 Pro with Media Center

MilesAhead

Eclectician
VIP Member
Pro User
More detail would help. With the current info it could just as well be accomplished with batch. Something like

Code:
For %s in (%1 %2 %3 %4) do {
dir %s >> results.txt
echo. >> results.txt
}

Some experimenting should do it
For - Looping commands | Windows CMD | SS64.com

name the batch DirThese.cmd
usage
DirThese fileone.txt file2.exe file3.xml

( or even better, use Shift to process as many files as you type on command tail )
 

My Computer

System One

  • OS
    Windows 8.0 x64
    Computer type
    Laptop
    System Manufacturer/Model
    Toshiba Satelite C55D-A Laptop
    CPU
    AMD EI 1200
    Memory
    4 gb DDR3
    Graphics Card(s)
    Raedon 340 MB dedicated Ram
    Monitor(s) Displays
    Built in
    Screen Resolution
    1366 x 768
    Hard Drives
    640 GB (spinner) Sata II
    Keyboard
    Built in
    Mouse
    Touch pad

Ztruker

Well-Known Member
VIP Member
Guru
crawfish, works like a charm. I tried | with grep and it didn't work. Does work correctly with egrep though.

So, one solution is to download and install UnxTools from the link I provided earlier then use dir piped to egrtep as crawfish showed.
 

My Computer

System One

  • OS
    Windows 10 Pro X64
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Lenovo IdeaCenter K450
    CPU
    Intel Quad Core i7-4770 @ 3.4Ghz
    Motherboard
    Lenovo
    Memory
    16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
    Graphics Card(s)
    Intel Integrated HD Graphics
    Sound Card
    Realtek HD Audio
    Monitor(s) Displays
    HP h2207
    Screen Resolution
    1680x1050@59Hz
    Hard Drives
    250GB Samsung EVO SATA-3 SSD;
    2TB Seagate ST2000DM001 SATA-2;
    1.5TB Seagate ST3150041AS SATA
    PSU
    500W
    Keyboard
    Wired USB
    Mouse
    Wired USB
    Internet Speed
    3GB Up, 30GB Down
    Browser
    SeaMonkey
    Antivirus
    Windows Defender; MBAM Pro
    Other Info
    UEFI/GPT
    PLDS DVD-RW DH16AERSH

MilesAhead

Eclectician
VIP Member
Pro User
It seems like Find would be ideal. Run Linux Find and for all files matching the pattern run command
ls -l

Some of the Linux ports may also let you run "Dos" commands in the shell. Maybe escaped somehow, if the actual Dir result is what is desired. Some have stand-alone exe Dos/Windows versions of Linux commands and others use a Bash shell for more sophisticated pattern matching; doing sed stream edits with patterns etc..

Depends how much the OP wants to do.

Edit: It may seem more convenient to avoid the bash shell, but it runs in a console window and is no big deal. The big advantage is you don't get tangled up with Windows directory separator backslashes messing up the patterns. You can get many cool sed and nawk "one liners" and run them without editing them. That pattern matching stuff as soon as you start to edit it then the patterns are untested. With bash you can just copy and paste them in.
 

My Computer

System One

  • OS
    Windows 8.0 x64
    Computer type
    Laptop
    System Manufacturer/Model
    Toshiba Satelite C55D-A Laptop
    CPU
    AMD EI 1200
    Memory
    4 gb DDR3
    Graphics Card(s)
    Raedon 340 MB dedicated Ram
    Monitor(s) Displays
    Built in
    Screen Resolution
    1366 x 768
    Hard Drives
    640 GB (spinner) Sata II
    Keyboard
    Built in
    Mouse
    Touch pad

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top