Hel lo everyone, I need help with bash commands.
Here is the deal :
I have several directories :
such as
JavaScript
x
path1/A/path2/
file1
file2
path1/B/path2/
file1
path1/C/path2/
file1
file2
path1/D/path2/
file1
file2
and a /path_to_this_file/file.txt
:
JavaScript
A
B
C
D
that I use such as :
JavaScript
cat /path_to_this_file/file.txt | while read line; do ls path1/$line/path2/
then I can list all content in the paths BUT I would like to do a ls only for the path2
that does not have a file2
into their directory..
Here only the path1/B/path2/
should be listed
Does someone have a code for that ?
Advertisement
Answer
Added an if statement to your code:
JavaScript
cat /path_to_this_file/file.txt |
while read line
do
if [ ! -f "path1/$line/path2/file2" ]; then
ls path1/$line/path2/
fi
done
Alternatively:
JavaScript
xargs -I {} bash -c "[ ! -f "path1/{}/path2/file2" ] && ls path1/{}/path2" < /path_to_this_file/file.txt