bash - Working on Files in Similarly (but differently) Named Directories -


i have 2 files on need run various commands. these 2 files have exact same name, in different folders. trouble in folder names. can count on these things in regards folders:

1) path leading folders same.

2) first folder include 1 hyphen in name.

a. before first hyphen same across servers.

b. after first hyphen different across servers, same on same server (like servername, not servername).

3) second folder include same name first folder, second hyphen along random set of characters.

here's more visual breakdown:

server01     /same/fld/path/dir1/                     |                     +--same-namex/                     |         |                     |         +--samefilename                     |                     +--same-namex-abc123/                               |                               +--samefilename  server02     /same/fld/path/dir1/                     |                     +--same-namey/                     |         |                     |         +--samefilename                     |                     +--same-namey-a1b2c3/                               |                               +--samefilename 

i'm scripting in bash, , i'm trying write script works regardless of server i'm running on.

so question is, how can formulate bash command (for simplicity, "cat") such authoritatively works on 1 file vs other?

for exampe, this:

cat /same/fld/path/dir1/same-*-*/samefilename 

this give me contents of "same-namex-abc123/samefilename"

however, this:

cat /same/fld/path/dir1/same-*/samefilename 

this won't work, because affect both files, , want work on file ".../same-namex/samefilename".

any appreciated.

to add additional clarity, question isn't related folder names single character difference. it's related folders different, differences lie between "hyphens". here examples:

server03     /same/fld/path/dir1/same-zxy12/samefilename     /same/fld/path/dir1/same-zxy12-xyz/samefilename  server04     /same/fld/path/dir1/same-g1f2e3d4/samefilename     /same/fld/path/dir1/same-g1f2e3d4-ab12c345/samefilename  server05     /same/fld/path/dir1/same-nmo/samefilename     /same/fld/path/dir1/same-nmo-ab/samefilename 

again, thank you, everyone, anyone, knowledge.

i recommend using extended glob match first file in each of cases:

shopt -s extglob # enable extended globbing cat /same/fld/path/dir1/same-!(*-)/samefilename 

this pattern match directory name not containing -.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -