linux - use value of wildcard in other parameter -


is there 1 line solution this?

i have many files , subdirectories in directory. simplification lets have

./dir1/file1 ./dir2/file2 ./file3 

i want run command each of files using wildcard (*) , use value of wildcard generate id of file in format dir_file , put parameter of command

e.g., for

command -file * -id <something> 

in case of 3 files example should called after expanding wildcard:

command -file ./dir1/file1 -id dir1_file1 command -file ./dir2/file2 -id dir2_file2 command -file file3 -id file3 

at least in bash not possible because:

after word splitting, unless -f option has been set, bash scans each word characters *, ?, , [. if 1 of these characters appears, word regarded pattern, , replaced alphabetically sorted list of file names matching pattern.

that means single * replaced list of files match pattern. try - after typing * in terminal press m-s-* (that means hold alt+shift+* together) , wildcard expanded.

you can achieve want using find, can unreadable pretty quickly:

find . -type f -name "*"  -exec bash -c 'command -file {} -id (echo {} | sed -e 's,\.,dot,' | sed -e 's,/,_,g' )'  \; 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -