Solved

Korn SHell script

Posted on 2001-08-07
11
628 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
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!

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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 how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

688 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