How to compare list of files with different extensions and delete extra files?Search for duplicate file names within folder hierarchy?Delete duplicate files with different extensionsHow to split the contents of a file?How can I delete all folders of a specific name without deleting Contents in it?How to delete all files except one named file from a specific folderzip multiple files with the same name but different extensionsregex to compare github links and list repos which end with the same name but have different ownerBash script to run python script for all images in all subdirectoriesHow to copy specific files in a list from subfolders to a folder?Create files if they don't already exist
How can I communicate my issues with a potential date's pushy behavior?
Piecewise convexity and global convexity
Why command hierarchy, if the chain of command is standing next to each other?
(A room / an office) where an artist works
Is there a way to proportionalize fixed costs in a MILP?
Will using a resistor in series with a LED to control its voltage increase the total energy expenditure?
Transition to "Starvation Mode" in Survival Situations
Would the USA be eligible to join the European Union?
"Mouth-breathing" as slang for stupidity
When was "Fredo" an insult to Italian-Americans?
A trip to the library
When did Bilbo and Frodo learn that Gandalf was a Maia?
Does fossil fuels use since 1990 account for half of all the fossil fuels used in history?
Why does cat'ing a file via ssh result in control characters?
Go to last file in vim
How did Arecibo detect methane lakes on Titan, and image Saturn's rings?
Telephone number in spoken words
In the movie Krull, what happened in the Spider Den?
Why does the cable resistance jump from a low value to high value at a particular frequency?
Is it possible to know the exact chord from the roman numerals
Finding the shaded region
Chunk + Enumerate a list of digits
How to not forget things?
Crippling fear of hellfire &, damnation, please help?
How to compare list of files with different extensions and delete extra files?
Search for duplicate file names within folder hierarchy?Delete duplicate files with different extensionsHow to split the contents of a file?How can I delete all folders of a specific name without deleting Contents in it?How to delete all files except one named file from a specific folderzip multiple files with the same name but different extensionsregex to compare github links and list repos which end with the same name but have different ownerBash script to run python script for all images in all subdirectoriesHow to copy specific files in a list from subfolders to a folder?Create files if they don't already exist
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have 2 folders one contains images files and the second contains text files each text file have the same name as the image file and contains information about the image.eg:
-Labels:
-1.txt
-2.txt
-3.txt
-6.txt
-Images:
-1.jpg
-2.jpg
-3.jpg
-4.jpg
-5.jpg
-6.jpg
I want to delete images who has not a text file(in this example:4.jpg,5.jpg), I found a method how to determinate the different files but I can't delete them.
diff <(ls -1 ./Images | sed s/.jpg//g) <( ls -1 ./Labels | sed s/.txt//g)
command-line bash
add a comment |
I have 2 folders one contains images files and the second contains text files each text file have the same name as the image file and contains information about the image.eg:
-Labels:
-1.txt
-2.txt
-3.txt
-6.txt
-Images:
-1.jpg
-2.jpg
-3.jpg
-4.jpg
-5.jpg
-6.jpg
I want to delete images who has not a text file(in this example:4.jpg,5.jpg), I found a method how to determinate the different files but I can't delete them.
diff <(ls -1 ./Images | sed s/.jpg//g) <( ls -1 ./Labels | sed s/.txt//g)
command-line bash
add a comment |
I have 2 folders one contains images files and the second contains text files each text file have the same name as the image file and contains information about the image.eg:
-Labels:
-1.txt
-2.txt
-3.txt
-6.txt
-Images:
-1.jpg
-2.jpg
-3.jpg
-4.jpg
-5.jpg
-6.jpg
I want to delete images who has not a text file(in this example:4.jpg,5.jpg), I found a method how to determinate the different files but I can't delete them.
diff <(ls -1 ./Images | sed s/.jpg//g) <( ls -1 ./Labels | sed s/.txt//g)
command-line bash
I have 2 folders one contains images files and the second contains text files each text file have the same name as the image file and contains information about the image.eg:
-Labels:
-1.txt
-2.txt
-3.txt
-6.txt
-Images:
-1.jpg
-2.jpg
-3.jpg
-4.jpg
-5.jpg
-6.jpg
I want to delete images who has not a text file(in this example:4.jpg,5.jpg), I found a method how to determinate the different files but I can't delete them.
diff <(ls -1 ./Images | sed s/.jpg//g) <( ls -1 ./Labels | sed s/.txt//g)
command-line bash
command-line bash
edited Aug 5 at 10:35
pa4080
16.3k7 gold badges34 silver badges81 bronze badges
16.3k7 gold badges34 silver badges81 bronze badges
asked Aug 2 at 15:22
oussama bousselmioussama bousselmi
415 bronze badges
415 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Here is a small bash script that can help you to solve this task:
#!/bin/bash
for file in Images/*.jpg
do
if [[ ! -f "Labels/$(basename $file%.*).txt" ]]
then
echo rm "$file"
fi
done
- Remove
echoto do the actual changes.
The script must be executed in the parent directory, here it is formatted as inline command:
for f in Images/*.jpg; do if [[ ! -f "Labels/$(basename $f%.*).txt" ]]; then echo rm "$f"; fi; done
thank you it works.
– oussama bousselmi
Aug 2 at 16:12
I am way too fond of sed, your solution is more elegant, thanks!
– Dries
Aug 2 at 16:15
Inzshyou can use$file:rinstead of$file%.*to get the filename minus one extension. It's smarter about what that means, which can be an advantage over substring matches when you're dealing with mixed paths that don't all fit a simple pattern. (e.g.file="foo.bar/baz"; echo $file:rwill returnfoo.bar/baz, notfoo. Thoughfile="foo.bar/.baz"will producefoo.bar/by either method, so some care is still required.)
– FeRD
Aug 3 at 3:06
add a comment |
I think I would do it like this:
for i in Images/*; do file=`echo $i | sed -e 's/jpg/txt/' -e 's/Images/Labels/'`; if [ ! -f "$file" ] ; then rm $i ; fi; done
If you want to make sure it works , before actually using it try this first:
for i in Images/*; do file=`echo $i | sed -e 's/jpg/txt/' -e 's/Images/Labels/'`; if [ ! -f "$file" ] ; then echo rm $i ; fi; done
It will show which commands will be executed.
add a comment |
cd /path/to/Images
LIST=$(find /path/to/Labels -iname *.txt -printf "%f|" | sed 's/.txt/.jpg/g')
rm -i !($LIST)
- Generates a list of
txtfiles. - Changes their extension to
jpg. Removes anything that is not on the list.
-iis just for safety.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1162948%2fhow-to-compare-list-of-files-with-different-extensions-and-delete-extra-files%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is a small bash script that can help you to solve this task:
#!/bin/bash
for file in Images/*.jpg
do
if [[ ! -f "Labels/$(basename $file%.*).txt" ]]
then
echo rm "$file"
fi
done
- Remove
echoto do the actual changes.
The script must be executed in the parent directory, here it is formatted as inline command:
for f in Images/*.jpg; do if [[ ! -f "Labels/$(basename $f%.*).txt" ]]; then echo rm "$f"; fi; done
thank you it works.
– oussama bousselmi
Aug 2 at 16:12
I am way too fond of sed, your solution is more elegant, thanks!
– Dries
Aug 2 at 16:15
Inzshyou can use$file:rinstead of$file%.*to get the filename minus one extension. It's smarter about what that means, which can be an advantage over substring matches when you're dealing with mixed paths that don't all fit a simple pattern. (e.g.file="foo.bar/baz"; echo $file:rwill returnfoo.bar/baz, notfoo. Thoughfile="foo.bar/.baz"will producefoo.bar/by either method, so some care is still required.)
– FeRD
Aug 3 at 3:06
add a comment |
Here is a small bash script that can help you to solve this task:
#!/bin/bash
for file in Images/*.jpg
do
if [[ ! -f "Labels/$(basename $file%.*).txt" ]]
then
echo rm "$file"
fi
done
- Remove
echoto do the actual changes.
The script must be executed in the parent directory, here it is formatted as inline command:
for f in Images/*.jpg; do if [[ ! -f "Labels/$(basename $f%.*).txt" ]]; then echo rm "$f"; fi; done
thank you it works.
– oussama bousselmi
Aug 2 at 16:12
I am way too fond of sed, your solution is more elegant, thanks!
– Dries
Aug 2 at 16:15
Inzshyou can use$file:rinstead of$file%.*to get the filename minus one extension. It's smarter about what that means, which can be an advantage over substring matches when you're dealing with mixed paths that don't all fit a simple pattern. (e.g.file="foo.bar/baz"; echo $file:rwill returnfoo.bar/baz, notfoo. Thoughfile="foo.bar/.baz"will producefoo.bar/by either method, so some care is still required.)
– FeRD
Aug 3 at 3:06
add a comment |
Here is a small bash script that can help you to solve this task:
#!/bin/bash
for file in Images/*.jpg
do
if [[ ! -f "Labels/$(basename $file%.*).txt" ]]
then
echo rm "$file"
fi
done
- Remove
echoto do the actual changes.
The script must be executed in the parent directory, here it is formatted as inline command:
for f in Images/*.jpg; do if [[ ! -f "Labels/$(basename $f%.*).txt" ]]; then echo rm "$f"; fi; done
Here is a small bash script that can help you to solve this task:
#!/bin/bash
for file in Images/*.jpg
do
if [[ ! -f "Labels/$(basename $file%.*).txt" ]]
then
echo rm "$file"
fi
done
- Remove
echoto do the actual changes.
The script must be executed in the parent directory, here it is formatted as inline command:
for f in Images/*.jpg; do if [[ ! -f "Labels/$(basename $f%.*).txt" ]]; then echo rm "$f"; fi; done
edited Aug 2 at 16:09
answered Aug 2 at 16:02
pa4080pa4080
16.3k7 gold badges34 silver badges81 bronze badges
16.3k7 gold badges34 silver badges81 bronze badges
thank you it works.
– oussama bousselmi
Aug 2 at 16:12
I am way too fond of sed, your solution is more elegant, thanks!
– Dries
Aug 2 at 16:15
Inzshyou can use$file:rinstead of$file%.*to get the filename minus one extension. It's smarter about what that means, which can be an advantage over substring matches when you're dealing with mixed paths that don't all fit a simple pattern. (e.g.file="foo.bar/baz"; echo $file:rwill returnfoo.bar/baz, notfoo. Thoughfile="foo.bar/.baz"will producefoo.bar/by either method, so some care is still required.)
– FeRD
Aug 3 at 3:06
add a comment |
thank you it works.
– oussama bousselmi
Aug 2 at 16:12
I am way too fond of sed, your solution is more elegant, thanks!
– Dries
Aug 2 at 16:15
Inzshyou can use$file:rinstead of$file%.*to get the filename minus one extension. It's smarter about what that means, which can be an advantage over substring matches when you're dealing with mixed paths that don't all fit a simple pattern. (e.g.file="foo.bar/baz"; echo $file:rwill returnfoo.bar/baz, notfoo. Thoughfile="foo.bar/.baz"will producefoo.bar/by either method, so some care is still required.)
– FeRD
Aug 3 at 3:06
thank you it works.
– oussama bousselmi
Aug 2 at 16:12
thank you it works.
– oussama bousselmi
Aug 2 at 16:12
I am way too fond of sed, your solution is more elegant, thanks!
– Dries
Aug 2 at 16:15
I am way too fond of sed, your solution is more elegant, thanks!
– Dries
Aug 2 at 16:15
In
zsh you can use $file:r instead of $file%.* to get the filename minus one extension. It's smarter about what that means, which can be an advantage over substring matches when you're dealing with mixed paths that don't all fit a simple pattern. (e.g. file="foo.bar/baz"; echo $file:r will return foo.bar/baz, not foo. Though file="foo.bar/.baz" will produce foo.bar/ by either method, so some care is still required.)– FeRD
Aug 3 at 3:06
In
zsh you can use $file:r instead of $file%.* to get the filename minus one extension. It's smarter about what that means, which can be an advantage over substring matches when you're dealing with mixed paths that don't all fit a simple pattern. (e.g. file="foo.bar/baz"; echo $file:r will return foo.bar/baz, not foo. Though file="foo.bar/.baz" will produce foo.bar/ by either method, so some care is still required.)– FeRD
Aug 3 at 3:06
add a comment |
I think I would do it like this:
for i in Images/*; do file=`echo $i | sed -e 's/jpg/txt/' -e 's/Images/Labels/'`; if [ ! -f "$file" ] ; then rm $i ; fi; done
If you want to make sure it works , before actually using it try this first:
for i in Images/*; do file=`echo $i | sed -e 's/jpg/txt/' -e 's/Images/Labels/'`; if [ ! -f "$file" ] ; then echo rm $i ; fi; done
It will show which commands will be executed.
add a comment |
I think I would do it like this:
for i in Images/*; do file=`echo $i | sed -e 's/jpg/txt/' -e 's/Images/Labels/'`; if [ ! -f "$file" ] ; then rm $i ; fi; done
If you want to make sure it works , before actually using it try this first:
for i in Images/*; do file=`echo $i | sed -e 's/jpg/txt/' -e 's/Images/Labels/'`; if [ ! -f "$file" ] ; then echo rm $i ; fi; done
It will show which commands will be executed.
add a comment |
I think I would do it like this:
for i in Images/*; do file=`echo $i | sed -e 's/jpg/txt/' -e 's/Images/Labels/'`; if [ ! -f "$file" ] ; then rm $i ; fi; done
If you want to make sure it works , before actually using it try this first:
for i in Images/*; do file=`echo $i | sed -e 's/jpg/txt/' -e 's/Images/Labels/'`; if [ ! -f "$file" ] ; then echo rm $i ; fi; done
It will show which commands will be executed.
I think I would do it like this:
for i in Images/*; do file=`echo $i | sed -e 's/jpg/txt/' -e 's/Images/Labels/'`; if [ ! -f "$file" ] ; then rm $i ; fi; done
If you want to make sure it works , before actually using it try this first:
for i in Images/*; do file=`echo $i | sed -e 's/jpg/txt/' -e 's/Images/Labels/'`; if [ ! -f "$file" ] ; then echo rm $i ; fi; done
It will show which commands will be executed.
edited Aug 2 at 16:06
pa4080
16.3k7 gold badges34 silver badges81 bronze badges
16.3k7 gold badges34 silver badges81 bronze badges
answered Aug 2 at 16:02
DriesDries
1181 silver badge9 bronze badges
1181 silver badge9 bronze badges
add a comment |
add a comment |
cd /path/to/Images
LIST=$(find /path/to/Labels -iname *.txt -printf "%f|" | sed 's/.txt/.jpg/g')
rm -i !($LIST)
- Generates a list of
txtfiles. - Changes their extension to
jpg. Removes anything that is not on the list.
-iis just for safety.
add a comment |
cd /path/to/Images
LIST=$(find /path/to/Labels -iname *.txt -printf "%f|" | sed 's/.txt/.jpg/g')
rm -i !($LIST)
- Generates a list of
txtfiles. - Changes their extension to
jpg. Removes anything that is not on the list.
-iis just for safety.
add a comment |
cd /path/to/Images
LIST=$(find /path/to/Labels -iname *.txt -printf "%f|" | sed 's/.txt/.jpg/g')
rm -i !($LIST)
- Generates a list of
txtfiles. - Changes their extension to
jpg. Removes anything that is not on the list.
-iis just for safety.
cd /path/to/Images
LIST=$(find /path/to/Labels -iname *.txt -printf "%f|" | sed 's/.txt/.jpg/g')
rm -i !($LIST)
- Generates a list of
txtfiles. - Changes their extension to
jpg. Removes anything that is not on the list.
-iis just for safety.
edited Aug 2 at 16:22
answered Aug 2 at 16:15
RavexinaRavexina
35.7k14 gold badges97 silver badges126 bronze badges
35.7k14 gold badges97 silver badges126 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1162948%2fhow-to-compare-list-of-files-with-different-extensions-and-delete-extra-files%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown