Solved

Korn SHell script

Posted on 2001-08-07
11
605 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
prtdiag report hdd failure 10 137
sudo logging 5 79
Help stop mail server from sending spam. 27 122
cron job says it ran, no results 25 114
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…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now