Solved

Korn SHell script

Posted on 2001-08-07
11
623 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
Industry Leaders: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unistall fileset without dependecies on AIX 3 71
Using Grep to Find a file 8 107
add some character at the end of line in vi 7 110
UNIX Script. Send email if failure 8 64
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

726 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