Solved

Korn SHell script

Posted on 2001-08-07
11
596 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
Comment Utility
directory name is
main_dir
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
Comment Utility
>> 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
Comment Utility
what looks your Filelist.lst like?
0
 

Author Comment

by:sarika1977
Comment Utility
It contains two file names like

srk.sh
srkStatq.sh

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
It works great. Thank you very much.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

762 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

6 Experts available now in Live!

Get 1:1 Help Now