Skip to main content
deleted 52 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 238

Not a newbie to coding, but definitely new to bash. I currently have a directory of files that looks something like this:

abcd.txt
abcd_.txt
qrst.txt
qrst_.txt
wxyz.txt
wxyz_.txt

In theory, every line in abcde_.txt should be contained in abcd.txt, and every line in qrst_.txt should be contained in qrst.txt, and so on. While I have no problem comparing two files to test for this individually, I'm trying to find a more efficient way to do this for the entire directory.

In a case like this, if I had a lot of pairs of files, but I didn't know in advance what string of letters they'd each start with, is there a way to loop through and process each set of two related files at a time?

Not a newbie to coding, but definitely new to bash. I currently have a directory of files that looks something like this:

abcd.txt
abcd_.txt
qrst.txt
qrst_.txt
wxyz.txt
wxyz_.txt

In theory, every line in abcde_.txt should be contained in abcd.txt, and every line in qrst_.txt should be contained in qrst.txt, and so on. While I have no problem comparing two files to test for this individually, I'm trying to find a more efficient way to do this for the entire directory.

In a case like this, if I had a lot of pairs of files, but I didn't know in advance what string of letters they'd each start with, is there a way to loop through and process each set of two related files at a time?

I currently have a directory of files that looks something like this:

abcd.txt
abcd_.txt
qrst.txt
qrst_.txt
wxyz.txt
wxyz_.txt

In theory, every line in abcde_.txt should be contained in abcd.txt, and every line in qrst_.txt should be contained in qrst.txt, and so on. While I have no problem comparing two files to test for this individually, I'm trying to find a more efficient way to do this for the entire directory.

In a case like this, if I had a lot of pairs of files, but I didn't know in advance what string of letters they'd each start with, is there a way to loop through and process each set of two related files at a time?

Source Link

Comparing directory files based on filename

Not a newbie to coding, but definitely new to bash. I currently have a directory of files that looks something like this:

abcd.txt
abcd_.txt
qrst.txt
qrst_.txt
wxyz.txt
wxyz_.txt

In theory, every line in abcde_.txt should be contained in abcd.txt, and every line in qrst_.txt should be contained in qrst.txt, and so on. While I have no problem comparing two files to test for this individually, I'm trying to find a more efficient way to do this for the entire directory.

In a case like this, if I had a lot of pairs of files, but I didn't know in advance what string of letters they'd each start with, is there a way to loop through and process each set of two related files at a time?