?
Solved

Korn SHell script

Posted on 2001-08-07
11
Medium Priority
?
632 Views
Last Modified: 2010-04-21
I have a directory like.

main_dir -
contains some files. One file 'Filelist.lst' conatins the name of the files to be moved to the new directory.

I need a korn shell script to take filenames from a file.
Creat a directory with datestamp and move the files listed in file 'Filelist.lst' to the newly created directory.

Thanks
0
Comment
Question by:sarika1977
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 

Author Comment

by:sarika1977
ID: 6359316
directory name is
main_dir
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6359975
cd main_dir
d=new_dir-`date +%Y%m%d`
mkdir $d
awk '{printf("mv %s %s\n",$0,'$d')}' Filelist.lst'|sh
0
 

Author Comment

by:sarika1977
ID: 6360627
>> awk '{printf("mv %s %s\n",$0,'$d')}' Filelist.lst'|sh

This prompts the following sign(maybe secondary command prompt)
>

even if i print enter, it again prompts
>


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 6360650
what looks your Filelist.lst like?
0
 

Author Comment

by:sarika1977
ID: 6360667
It contains two file names like

srk.sh
srkStatq.sh

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6360721
cd main_dir
d=new_dir-`date +%Y%m%d`
mkdir $d
awk '{printf("mv %s %s\n",$0,'$d')}' Filelist.lst|sh

# there was a wrong ' behind the  Filelist.lst, sorry
0
 

Author Comment

by:sarika1977
ID: 6360820
Now it says

mv: Insufficient arguments (1)                      
Usage: mv [-e ignore|warn|force] [-fi] f1 f2        
       mv [-e ignore|warn|force] [-fi] f1 ... fn d1  
       mv [-e ignore|warn|force] [-fi] d1 d2        

I am not much familiar with awk.
How does $0 gets mapped to filename. and why are you piping output to sh?
Thanks
0
 

Author Comment

by:sarika1977
ID: 6360901
Now it says

mv: Insufficient arguments (1)                      
Usage: mv [-e ignore|warn|force] [-fi] f1 f2        
       mv [-e ignore|warn|force] [-fi] f1 ... fn d1  
       mv [-e ignore|warn|force] [-fi] d1 d2        

I am not much familiar with awk.
How does $0 gets mapped to filename. and why are you piping output to sh?
Thanks
0
 

Author Comment

by:sarika1977
ID: 6360903
Now it says

mv: Insufficient arguments (1)                      
Usage: mv [-e ignore|warn|force] [-fi] f1 f2        
       mv [-e ignore|warn|force] [-fi] f1 ... fn d1  
       mv [-e ignore|warn|force] [-fi] d1 d2        

I am not much familiar with awk.
How does $0 gets mapped to filename. and why are you piping output to sh?
Thanks
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 400 total points
ID: 6361111
aargh, should switch my shell ... sorry.

please replace awk line as follows

    awk '{printf("mv %s '$d'\n",$0)}' Filelist.lst|sh

> How does $0 gets mapped to filename.
awk reads the given file, each line is stored in awk variable $0.

> and why are you piping output to sh?
this little awk program generates the shell mv commands (simply call it without  |sh), these commands are piped to a shell which then executes them.
0
 

Author Comment

by:sarika1977
ID: 6361326
It works great. Thank you very much.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question