Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7519295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:52:44+00:00 2026-05-30T01:52:44+00:00

First I would like to generate a directory listing for all text files in

  • 0

First I would like to generate a directory listing for all text files in a directory. Next take each of those text files and get-contents. Then I want to go through the contents and search for all text files in another directory which share contents with the first file and output those corresponding matches to a file named after the source file.

I’m very new at all of this and realize I’m missing some serious fundamental chunks of knowledge. What little scripting experience I have is in Javascript which doesn’t seem entirely transferable. (Although programming is programming I’m told.)

This is what I have so far:

$max = get-content h:test1\one.txt | Measure-Object
$A = get-content h:test1\one.txt
For($i=0; $i -lt $max.count ; $i++){
    select-string h:test2\*.txt -pattern $($A[$i]) | Format-Table | Out-File ($i + '.txt')
    }

I’m hoping for something like:

$max = get-content $files[i] | Measure-Object
    $A = get-content files[i]
    For($j=0; $j -lt $max.count ; $j++){
        select-string h:test2\*.txt -pattern $($A[$j]) | Format-Table | Out-File($files[i].basename + $j + '.txt')
    }

Any and all help would be extremely appreciated,

Kurtis

So

Book 1 (one.txt)

The capital of France is Paris.
The population of Paris is twelve.

Book 2 (two.txt)

France is a beautiful country.
The capital of France is Paris.

I basically want a report of the fact that two.txt shares a line with one.txt.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:52:46+00:00Added an answer on May 30, 2026 at 1:52 am

    OK let’s break this down:

    First I would like to generate a directory listing for all text files in a directory. Next take each of those text files and get-contents.

    dir *.txt | get-content
    

    Then I want to go through the contents and search for all text files
    in another directory which share contents with the first file

    OK, now we pipe all that text to select-string (first filtering out all empty string with ?{$_}:

    dir *.txt | get-content | ?{$_} | %{select-string -path searchPath\*.txt -pattern "$_" -simple}
    

    and output those corresponding matches to a file named after the
    source file.

    So now it gets tricky because we have to go back and track our source file name, we do this by wraqpping our query in a foreach (i.e. %{} ):

    dir *.txt | %{ $sourceFile = $_; get-content $_ | ?{$_} | %{select-string -path searchPath\*.txt -pattern "$_" -simple} | out-file "$sourceFile.results" }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get the first item from a list matching a condition.
I would like to produce a character list of all of the first letters
I would like to get some feedback on what is one of my first
i would like to generate strict alphanumeric character logins from users' first and lastname.
First I would like to say that I am new to this site, never
I've been thinking about playing with Java3D . But first I would like to
I would like to replace the first character ' x ' with the number
I would like to make a First Access Database Setup Process in my spring
I would like to search my table having a column of first names and
I would like to run multiple copies of my application and force the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.