Creating a filelist


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a filelist
# 1  
Old 09-22-2011
Creating a filelist

I need a script that will read a filename and verify that its today's file and rename it to a standard name so that my ETL job can read it on a daily basis. If there is no file for a day, I am thinking I will just read the one before to prevent my job from failing. Another option might be a filelist and I have the option of doing an indirect read as well (If there is a better way to do this please suggest).

The filename does have the date appended to it.

So, for example the name of the file for today will be something like:

xyz_20110922.txt

I need to take this and convert it as xyz.txt

Thank you in advance!
# 2  
Old 09-22-2011
Try this...

Code:
ls * | awk -v date=`date +%G%m%e` '{if($0~date){file=$0;gsub("_"date,"");system("mv "file" "$0)}}'

--ahamed

---------- Post updated at 02:10 PM ---------- Previous update was at 02:08 PM ----------

or you can echo the file name and pipe it to awk

Code:
echo $file_name | awk ...

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find the files based on date from filelist

Hi All, I have a filelist which contains the "ls" output, i want to extract the filenames written in this files based on date. I know i can run loop and extract the file but i want to avoid it. also there is find command which can be used on directory i.e. find . -type f -newermt "2019-09-25"... (3 Replies)
Discussion started by: kumarinfa
3 Replies

2. Shell Programming and Scripting

Get filelist in a folder which is created in last x hours

Hi , I am looking for some help in getting the list of files matching some pattern in a folder and those were created in last X hours. Please help. Thanks in advance. (1 Reply)
Discussion started by: Anupam_Halder
1 Replies

3. UNIX for Dummies Questions & Answers

Get filelist.txt from a sftp remote server

Hi everyone, so I have a script create a login file to log into the sftp remote server, go to a certain directory and get the list of files in that direction into a text file in another folder (local folder). Here is the piece of code echo "#!/usr/local/bin/expect -f" >>... (5 Replies)
Discussion started by: warmboy610
5 Replies

4. Shell Programming and Scripting

move files defined in filelist

Hi, I have a filelist named filestomove.txt. It can contain any number of files that need to be moved to a subdirectory. All the files from filelist are in the same directory as the filelist, let say it's called Folder1. All the files need to be moved to subfolder Folder1/Subfolder1. ... (1 Reply)
Discussion started by: kedrick
1 Replies

5. Shell Programming and Scripting

awk filelist containing strange characters

I've written a script: find -depth | awk ‘ { if ( substr($1,length($0)-2,3) == “/1.” ) { print $1 } { system(“awk -f test1.awk “ $1 ) } } ‘ The idea is that it trundles through a large directory structure looking for files which are named '1.' and then... (3 Replies)
Discussion started by: nashcom
3 Replies

6. Shell Programming and Scripting

Fastest way to delete duplicates from a large filelist.....

OK I have two filelists...... The first is formatted like this.... /path/to/the/actual/file/location/filename.jpg and has up to a million records The second list shows filename.jpg where there is more then on instance. and has maybe up to 65,000 records I want to copy files... (4 Replies)
Discussion started by: Bashingaway
4 Replies

7. UNIX for Dummies Questions & Answers

Help on cat filelist.txt |xargs -n1 find

I am trying to find all the files listed in a filelist.txt. Why cant I use something like this cat filelist.txt | xargs -n1 find $path (2 Replies)
Discussion started by: dragonpoint
2 Replies

8. Shell Programming and Scripting

i want to combine two awk scripts which is having same loop and filelist

hi, to all give me some idea below scripts file=`cat filelist` for filename in $file do awk '{ if ($0 ~ /system/ && flag == 0) { flag=1; print $0; } else if ($0 ~ /system/ && flag == 1) { printf("%s SYSLAY %s %s %s\n",$1,$3, $4, $5); } else print $0; }' $filename >... (6 Replies)
Discussion started by: LAKSHMI NARAYAN
6 Replies

9. UNIX for Dummies Questions & Answers

chmod - pass a filelist as a parameter?

Hi I have a text file which contains a list of file names (one file name per line). I would like to pass the contents of this file into chmod to change the permissions. I am having trouble getting the correct syntax for this. Can someone please tell me if its possible to do this? Thanks (2 Replies)
Discussion started by: alangibson
2 Replies

10. Shell Programming and Scripting

how to get nth file filelist

hi all, kindly help me in getting nth file from file list ls load*.txt > filelist.txt #filelist.txt contains list of files starts with load as filename now i am required to get one by one from filelist.txt for further processing, kindly let me know how to get it. thanks in advance -Bali (1 Reply)
Discussion started by: balireddy_77
1 Replies
Login or Register to Ask a Question