Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple question about moving file, help pls... 1

Status
Not open for further replies.

h3nd

Programmer
Jul 1, 2006
147
AU
Hi guys,

I've got list files in directory like this ...
mycron20060701
Timing20060701
Timing20060703
Timing20060703
CheckMissingFiles20060706
datacompare20060706
datasirs20060706
data20060706
ExcelCheckIncomingFileSize.ksh20060707
Report20060707
Timing20060707
Timing20060707

basically, I want to group them according to their suffix and create directory with their suffix name, so particular files will be move to the particular directory.

So, the script will group the files with the suffix *20060701, create the 20060701 directory and then move them to directory "20060701", and same with other suffix date.

Thx guys in advance
 
Hi

Code:
for f in *; do
  dir=`echo $f | sed 's/.*\(.\{8\}\)$/\\1/'`

[gray]# uncomment the next command, if you want path like this :[/gray]
[gray]# 2006/07/01/mycron20060701[/gray]

[gray]#  dir=`echo "$f" | sed 's/.*\(....\)\(..\)\(..\)$/\\1\/\\2\/\\3/'`[/gray]

  test -x "$dir" || mkdir -p "$dir"
  mv "$f" "$dir"
done

Feherke.
 
Great,

But I think the code
Code:
dir=`echo $f | sed 's/.*\(.\{8\}\)$/\\1/'`

should be

Code:
dir=`echo $f | sed 's/.*\(.\{8\}\)$/\1/'`

anyway, Thanks for your idea
Have a star
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top