logo
down
shadow

Renaming files in folder and subfolders using a list- Bash Script/Unix


Renaming files in folder and subfolders using a list- Bash Script/Unix

By : user2949072
Date : November 16 2020, 06:23 AM
it should still fix some issue To use a batch mv command you'll need to create a tab separated file that'll add explicitly the directory structure that your replace.txt misses, like so:
code :
full/path/old.stuff<TAB>full/path/new.stuff
find . > all_paths.ls
for path in `cat all_paths.ls` ; do basename $path ; done > all_names.ls
for path in `cat all_paths.ls` ; do dirname $path ; done > all_dirs.ls
paste all_names.ls all_dirs.ls > all_name-dir.tsv
sort replace.txt > replace.sorted.txt
sort all_name-dir.tsv > all_name-dir.sorted.tsv
# join will work fine because "old basenames" are in the first column of both tables
join -t "<TAB>" all_name-dir.sorted.tsv replace.sorted.txt > todo_name-dir-newname.tsv
old.stuff<TAB>full/path/<TAB>new.stuff
# get the columns back
cut -f2 < todo_name-dir-newname.tsv > todo_dirs.ls
cut -f1 < todo_name-dir-newname.tsv > todo_oldnames.ls
cut -f3 < todo_name-dir-newname.tsv > todo_newnames.ls

# glue 2 and 1 together for reconstructed old paths
paste todo_dirs.ls todo_oldnames.ls | tr "\t" "/" > todo_oldpaths.ls

# same for the new ones
paste todo_dirs.ls todo_newnames.ls | tr "\t" "/" > todo_newpaths.ls

# and we get the table we wanted
paste todo_oldpaths.ls todo_newpaths.ls > replace_table.tsv
for line in `cat replace_table.tsv`
 do oldpath=`echo $line | cut -f1`
    newpath=`echo $line | cut -f2`
    mv $oldpath $newpath
 done


Share : facebook icon twitter icon
Renaming folders, files and subfolders in bash

Renaming folders, files and subfolders in bash


By : user3773572
Date : March 29 2020, 07:55 AM
it fixes the issue I have a problem with a bash script... I want to rename all files, folders and subfolders in a recursive manner, from lower-case to upper-case (or viceversa). I've wrote this script, but it doesn't work. , Why not use a simple while-loop:
code :
find testdir/ -depth | while read file; do NEWNAME=$(dirname "$file")/$(echo $(basename "$file") | tr '[:lower:]' '[:upper:]'); mv "$file" "$NEWNAME"; done
Bash script issue with renaming files from folder name

Bash script issue with renaming files from folder name


By : Cullen_Cui
Date : March 29 2020, 07:55 AM
seems to work fine I have a bash script that does not produce the result I expected. It is intended to rename files in a folder structure in such a way that the files are sortable outside the folder structure. , Reformatted and repaired.
code :
cd "$@"
pwd
IFS=$'\n'
for f in $(find "$PWD" -name '*.wav'); do
  folder=${f%/*}
  file=${f##*/}
  echo ${folder##*/}"/"$file "-->" ${folder##*/}$(printf %03d "$(( 10#${file%% *} ))") ${file#* } >> rename_log.out
  mv "$f" "$folder/${folder##*/}$(printf %03d "$(( 10#${file%% *} ))") ${file#* }"
done
Bash script for renaming files and moving into different folder

Bash script for renaming files and moving into different folder


By : D Elmas
Date : March 29 2020, 07:55 AM
this will help You can achieve this by using a counter and a for..in..do...done loop.
Here's an example:
code :
#!/bin/bash

FILES=./files/*
TARGET=~/Desktop/dist # make sure that folder exists!
COUNTER=1 # if you want to start from 0, just put 0 there
for f in $FILES
do
  echo "Processing $f file..."
  mv $f $TARGET/$COUNTER"_"${f##*/}
  let "COUNTER++"
done
bash shell: recursively search folder and subfolders for files from list

bash shell: recursively search folder and subfolders for files from list


By : Zach
Date : March 29 2020, 07:55 AM
like below fixes the issue Until now when I want to gather files from a list I have been using a list that contains full paths and using: , Try something like
code :
find folder_to_search -type f | grep -f pattern_file | xargs -I % cp % folder
Bash script to move all png files in folder and its subfolders to another directory?

Bash script to move all png files in folder and its subfolders to another directory?


By : ATH
Date : March 29 2020, 07:55 AM
With these it helps I guess that these image filenames maybe include spaces or other special characters.
code :
find ~/Desktop/a/ -type f -name "*.png" -exec mv "{}" ~/Desktop/new/ \;
find ~/Desktop/a/ -type f -name "*.png" -print0 | xargs -0 -I{} mv "{}" ~/Desktop/new/
Related Posts Related Posts :
  • how to delete duplicate lines in a text file in unix bash?
  • Compare a variables in bash
  • How do I use sed on a string?
  • Using bash variables for range in sed
  • convert a DURATION HH:MM:SS to seconds in bash
  • Shell make system paths click-able when printed out by my shell script
  • I want to use parallel-ssh to run a bash script on multiple servers, but it simple prints the echo statements
  • AWK between 2 patterns - first occurence
  • Nginx on docker - daemonize and attach to bash
  • Delete or Replace nth line in a file after a pattern match using shell scripts
  • Actual return code for SCP
  • How to exit a bash function that expects a return
  • Bash script to split file into two files while changing output file during processing
  • Pass command line arguments via sbatch
  • variable substitution (what do you call/name this method)?
  • Call function from another shell script
  • How to Grep and Replace With Exclusions
  • shell command to remove characters after a special character in bash/shell
  • How do I run a script for 1st working day of every month in cron?
  • Bash Unexpected End of File Error After Installing RVM
  • Nested Loop with increment on inner loop?
  • video orientation detection in bash
  • Interrupt sleep in bash with a signal trap
  • Want file rename script to add number at end with fixed length
  • What's the DRYest way to replace a file with a symlink in bash
  • How to run Bitcoin's autogen.sh file?
  • Bash command to compare more than two files
  • If It is a directory append text
  • What's wrong with my WHILE-DO loop, or why my script can't find the file I'm giving it on a plate?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org