subset files in a folder based on a list

biobudhan

I have a folder "all_images/" with more than 1000 image files named as "Image1.tif", "Image2.tif" and so on..

I have a text file "extract_images_list.txt" which is a list of images that I want to extract from this folder.

Example:

Image23.tif

Image100.tif

Image248.tif

I want to move only those files mentioned in my text file to another folder "extract_images/"

I could only think of

  rm (Image1|Image2|Image3|...|...|....|)

where I would provide the images that I don't want.

Is there a better way of doing this?

Muzer

With the caveat that this solution can't possibly handle things like the Line Feed character being in a filename:

mkdir extract_images 2>/dev/null
while IFS= read -r file; do
  mv "$file" extract_images
done < extract_images_list.txt

This goes through extract_images_list.txt line-by-line by reading them into the file variable (the -r argument is required to make it treat backslashes as literal backslashes, and IFS= makes it not strip whitespace), then moves each line to the extract_images directory.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Move all files from one folder to another, based on a list

From Dev

Move all files with matching prefixes to folder based on a csv list

From Dev

Subset list based on a condition in R

From Dev

How to list files in folder

From Dev

List files in a folder to a JOptionPane

From Dev

Subset items in list of list based on indices

From Dev

Move and rename files based on the folder they are in

From Dev

Rename Files Based On Folder Name

From Dev

Rename files based on folder name

From Dev

Subset a data frame based on elements in a list

From Dev

Return dataframe subset based on a list of boolean values

From Dev

Subset a data frame based on elements in a list

From Dev

Using Browserify on only a subset of files in a folder within a Gulp task

From Dev

Search for files based on a list of partial names and copy them to a destination folder using windows shell

From Java

Getting list of files in documents folder

From Dev

list.files - exclude folder

From Dev

Get an ordered list of files in a folder

From Dev

Loop through a folder and list files

From Dev

Rails - List of Files inside a folder

From Dev

How to list files names in folder

From Dev

xml files from folder into list

From Dev

Rename files based on list

From Dev

Delete files from a folder based on another file

From Dev

Enumerate files from a folder based on tags/keywords

From Dev

Ignoring files based on project folder name

From Dev

Powershell: Move files to folder based on Date Created

From Dev

Move files to folder based on parts of filename

From Dev

Rename folder of files based on file content

From Dev

Moving files in python based on file and folder name

Related Related

HotTag

Archive