LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-24-2017, 05:27 AM   #1
Asoo
LQ Newbie
 
Registered: Apr 2017
Posts: 29

Rep: Reputation: Disabled
Creating folders and moving files in shell script


Hi,

I want to create folders and move the files into folder using shell script. For example, I have 50,000 files (choose only the specific extnsion), I want to create 50 folders, each having 1000 files. The files are named like 1.txt, 2.txt ... , 50000.txt. So 1.txt-1000.txt should be in folder 1, 1001.txt-2000.txt should be in folder 2 and so on...

My test code that runs on only 10 sample txt files is below:

Code:
end=2
begin=1
for i in {1..5}
do
	mkdir "$i"
	for file in *.txt:
	do
		mv "{$begin..$end}.txt" "$i"
	done
	end=$((end+2))
	begin=$((begin+2))

done
It gives error,'mv: cannot stat '{1..10}.txt': No such file or directory'. I am able to create directories but cannot move the files into specified folders.

Thanks in advance.
 
Old 05-24-2017, 06:38 AM   #2
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 759

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Debug advice: use echo in place of your mv; use shell -vx switches.

p.s. Please mark your prior thread resolved, via ThreadTools, at top.
Thanks and best wishes for success. Welcome to LQ

Last edited by !!!; 05-24-2017 at 06:43 AM.
 
1 members found this post helpful.
Old 05-24-2017, 07:48 AM   #3
Asoo
LQ Newbie
 
Registered: Apr 2017
Posts: 29

Original Poster
Rep: Reputation: Disabled
Thank you for the reply.

I used "eval" and it worked.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help creating script to process files in folders jkellogg Linux - General 4 08-01-2016 07:45 AM
Using rm in Bash shell script on files/folders with spaces in for loop array kayasaman Programming 18 05-16-2013 06:34 AM
Shell Script to compare folders,Sub-Folders and Sub-Sub-Folders unix_72427 Programming 8 08-08-2012 02:51 PM
Shell script on copying files and folders from a linux server to a windows server nithin6034 General 6 07-20-2011 07:59 AM
Shell script to delete folders and files dynamically and recursively rjbaca Linux - General 1 06-21-2010 11:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration