mac_g
asked on
shell script : moving files to other folder after grep fiter
i have some hundreds of file in directory of our application
each file has 2/3 file extention in directory,
example :
file01.ext1,
file01.ext2
file01.ext3
----
to simply which file, have how many counts , I am using below script
ls |awk -F"." '{print $1}'|uniq -c | awk '+$1 == 3'
The above shell script which display output in below format, for the current directory files..... working well.
---- O/P from the above script -------------
3 file01
3 file02
2 file03
----------------
where
Column-1, file count of its different file extension
column-2, is filename,
now ...I need
i want to move files into some directory, which has count=3
please advice the needed enhancement
each file has 2/3 file extention in directory,
example :
file01.ext1,
file01.ext2
file01.ext3
----
to simply which file, have how many counts , I am using below script
ls |awk -F"." '{print $1}'|uniq -c | awk '+$1 == 3'
The above shell script which display output in below format, for the current directory files..... working well.
---- O/P from the above script -------------
3 file01
3 file02
2 file03
----------------
where
Column-1, file count of its different file extension
column-2, is filename,
now ...I need
i want to move files into some directory, which has count=3
please advice the needed enhancement
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
One small comment on the accepted answer - you need the dot after the filename in the "mv" command (as I had in my answer #a40003432)
file1.ext1
file1.ext2
file1.ext3
file10.ext
in your input directory, the accepted answer would copy the file10.ext1 file, because it matched "file1*", even though there was only one file with the file10 prefix.
for file in `ls |awk -F"." '{print $1}'|uniq -c | awk '+$1 == 3{print $2}'`
do
mv $file.* targetdir
done
If you have, for example:file1.ext1
file1.ext2
file1.ext3
file10.ext
in your input directory, the accepted answer would copy the file10.ext1 file, because it matched "file1*", even though there was only one file with the file10 prefix.
Well picked up Simon.
ASKER
tintin...
I did not see while choose the solution ..
apologies ... you deserve most
I did not see while choose the solution ..
apologies ... you deserve most
No problem. Only spotted it because I'd been hit by the same bug recently!
ASKER
altered your script to
-----
for file in `ls |awk -F"." '{print $1}'|uniq -c | awk '+$1 == 3' | grep -x 3 | awk '{ print $2 }'`
do
mv $file.* ./temp
done
----
no files has moved ..
any idea how to fix this issue