I do not have programming experience and mostly use one-liner or sometimes more to get the job done. I am having problem to batch rename the files that do not match a particular pattern.
Sample file-names from directory:
Meeting_Packages.pdf 13_textfile0 19_textfile0 23_textfile0 29_textfile0 33_textfile1 45_textfile0 5_textfile3 Membership.pdf 13_textfile1 19_textfile1 23_textfile1 29_textfile1 34_textfile0 46_textfile0 6_textfile0 xyz2009.pdf 13_textfile2 19_textfile2 23_textfile2 29_textfile2 34_textfile1 47_textfile0 6_textfile1 meeting.ics
I want to rename the files i.e Meeting_Packages.pdf, Membership.pdf, meeting.ics and xyz2009.pdf to the file from where they came (input file). Actually it is output of 'ripmime' with mails as xx_textfilex and others are attachments. I want to name attachments as the original input file
My Code:
#!/bin/bash
1 FILES=*.mime
2 for f in $FILES
3 do
4 echo "Processing $f"
5 #rip mails into attachments and text files also add a prefix to text files
6 ripmime -i $f -d ~/test/ripmime --prefix
7 #Remove white spaces from files
8 rename 's/ /_/g' ~/test/ripmime/*
9 #rename attachments as original input files
10 rename 's/\[^0-9]/'$f/ ~/test/ripmime/*
11
12 done
My problem is line-10 where I try to filter files other then xx_textfilex and rename. I tried different REGEX could not do that. I can select and rename the textfiles by:
rename 's/textfiles/'$f/ ~/test/ripmime/*
But I need inverse of that and rename files other then textfiles.
How can I do this?