Bash: Use exec find option by sorting two file arguments
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
Let's say I want to compare the files with the same filename between these two directories:
/tmp/datadir/dir1/dir2/
and
/datadir/dir1/dir2/
It is required to sort them before comparing.
I am currently in the /tmp
directory, and I tried to run this find
with the exec
option:
find datadir -type f -exec sdiff -s <( sort ) <( sort "/" ) ;
But, it gives me an error
sort: open failed: : No such file or directory
sort: open failed: /: No such file or directory
However, the below command works fine, but the data is not sorted for proper comparison.
find data -type f -exec sdiff -s "/" ;
How can I fix this problem?
bash find sort
add a comment |Â
up vote
4
down vote
favorite
Let's say I want to compare the files with the same filename between these two directories:
/tmp/datadir/dir1/dir2/
and
/datadir/dir1/dir2/
It is required to sort them before comparing.
I am currently in the /tmp
directory, and I tried to run this find
with the exec
option:
find datadir -type f -exec sdiff -s <( sort ) <( sort "/" ) ;
But, it gives me an error
sort: open failed: : No such file or directory
sort: open failed: /: No such file or directory
However, the below command works fine, but the data is not sorted for proper comparison.
find data -type f -exec sdiff -s "/" ;
How can I fix this problem?
bash find sort
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Let's say I want to compare the files with the same filename between these two directories:
/tmp/datadir/dir1/dir2/
and
/datadir/dir1/dir2/
It is required to sort them before comparing.
I am currently in the /tmp
directory, and I tried to run this find
with the exec
option:
find datadir -type f -exec sdiff -s <( sort ) <( sort "/" ) ;
But, it gives me an error
sort: open failed: : No such file or directory
sort: open failed: /: No such file or directory
However, the below command works fine, but the data is not sorted for proper comparison.
find data -type f -exec sdiff -s "/" ;
How can I fix this problem?
bash find sort
Let's say I want to compare the files with the same filename between these two directories:
/tmp/datadir/dir1/dir2/
and
/datadir/dir1/dir2/
It is required to sort them before comparing.
I am currently in the /tmp
directory, and I tried to run this find
with the exec
option:
find datadir -type f -exec sdiff -s <( sort ) <( sort "/" ) ;
But, it gives me an error
sort: open failed: : No such file or directory
sort: open failed: /: No such file or directory
However, the below command works fine, but the data is not sorted for proper comparison.
find data -type f -exec sdiff -s "/" ;
How can I fix this problem?
bash find sort
edited Aug 7 at 15:41
Peter Mortensen
79148
79148
asked Aug 7 at 14:01
Kaushik Nayak
21316
21316
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
10
down vote
accepted
The replacement of is done by
find
and happens after the evaluation of the process substitution (<(…)
) and such in your code.
Using bash -c
:
find datadir -type f -exec
bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash ;
Or to avoid running one bash
instance per file:
find datadir -type f -exec bash -c '
for file do
sdiff -s <( sort "$file" ) <( sort "/$file" )
done' bash +
add a comment |Â
up vote
1
down vote
You could consider using the -r
(recursive) option that does all the sorting and recursing for you.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
accepted
The replacement of is done by
find
and happens after the evaluation of the process substitution (<(…)
) and such in your code.
Using bash -c
:
find datadir -type f -exec
bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash ;
Or to avoid running one bash
instance per file:
find datadir -type f -exec bash -c '
for file do
sdiff -s <( sort "$file" ) <( sort "/$file" )
done' bash +
add a comment |Â
up vote
10
down vote
accepted
The replacement of is done by
find
and happens after the evaluation of the process substitution (<(…)
) and such in your code.
Using bash -c
:
find datadir -type f -exec
bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash ;
Or to avoid running one bash
instance per file:
find datadir -type f -exec bash -c '
for file do
sdiff -s <( sort "$file" ) <( sort "/$file" )
done' bash +
add a comment |Â
up vote
10
down vote
accepted
up vote
10
down vote
accepted
The replacement of is done by
find
and happens after the evaluation of the process substitution (<(…)
) and such in your code.
Using bash -c
:
find datadir -type f -exec
bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash ;
Or to avoid running one bash
instance per file:
find datadir -type f -exec bash -c '
for file do
sdiff -s <( sort "$file" ) <( sort "/$file" )
done' bash +
The replacement of is done by
find
and happens after the evaluation of the process substitution (<(…)
) and such in your code.
Using bash -c
:
find datadir -type f -exec
bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash ;
Or to avoid running one bash
instance per file:
find datadir -type f -exec bash -c '
for file do
sdiff -s <( sort "$file" ) <( sort "/$file" )
done' bash +
edited Aug 7 at 14:17


Stéphane Chazelas
282k53520854
282k53520854
answered Aug 7 at 14:06


phk
3,80852147
3,80852147
add a comment |Â
add a comment |Â
up vote
1
down vote
You could consider using the -r
(recursive) option that does all the sorting and recursing for you.
add a comment |Â
up vote
1
down vote
You could consider using the -r
(recursive) option that does all the sorting and recursing for you.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You could consider using the -r
(recursive) option that does all the sorting and recursing for you.
You could consider using the -r
(recursive) option that does all the sorting and recursing for you.
answered Aug 7 at 17:42
RalfFriedl
2,8451519
2,8451519
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461080%2fbash-use-exec-find-option-by-sorting-two-file-arguments%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password