processing file names using text files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting processing file names using text files
# 1  
Old 12-01-2008
processing file names using text files

Hi,

I have to perform an iterative function on a set of 10 files. After the first round the output files are named differently than the input files.

examples

input file name = xxxx1.yyy
output file name = xxxx1_0001.yyy

I need to rename all of the output files to the original input name for reprocessing.

I have created two text files using ----

ls > output.txt
ls > input.txt

Now what I would like to do is assign line one of output to say $1 and input to $2 and then use the shell command

cp $1 $2

where the file listed on the first line of output.txt is cp to the file name givin in the first line of input.txt

and for this to be done for each line of the two files.

I have been trying to use an awk script

#!/usr/bin/awk -f
{d=$0}
{print d }


but I cannot figure out how to assign input file to "d" and output to "e" to then pass those variables to the shell cp command.

can anyone help me? and yes as you probably can tell, I'm very new at this.
# 2  
Old 12-01-2008
Hi,

if your filenames differ only in the _0001 part, i would suggest

Code:
for i in *yyy; do mv $i ${i//_*./.}; done

HTH Chris
# 3  
Old 12-01-2008
Hammer & Screwdriver

Helping with your awk statement, take a look at the following:

Code:
> ls file7*
file70  file71  file73  file73.n  file74  file75  file77  file78  file79
> ls file7* | awk 'd=$0 {print d}'
file70
file71
file73
file73.n
file74
file75
file77
file78
file79

However, I think you would be better off with a loop like the following:
Code:
> ls file7* >list7
> while read filename; do echo $filename ; done <list7
file70
file71
file73
file73.n
file74
file75
file77
file78
file79

Instead of an echo command, you could do your rename of the file.
# 4  
Old 12-01-2008
Thanks....yes...the names are somewhat more complex...I should have listed them as:
xxxx1.yyy
zzzz1_0001.yyy

Thanks for you reply
# 5  
Old 12-01-2008
Hammer & Screwdriver What about this thinking?

The following example
shows files that start file7
creates a file, by using awk, containing current names and desired new names
shows that work file
reads through the work file, copying from original to new names
shows that the files were just created

Code:
> ls file7*
file70  file71  file73  file74  file75  file77  file78  file79

> ls file7* | awk 'd=$0 {print d" "substr(d,1,4)"new"substr(d,5,2)}' >list7

> cat list7
file70 filenew70
file71 filenew71
file73 filenew73
file74 filenew74
file75 filenew75
file77 filenew77
file78 filenew78
file79 filenew79

> while read file1 file2; do cp $file1 $file2; done <list7

> ls filenew*
filenew70  filenew71  filenew73  filenew74  filenew75  filenew77  filenew78  filenew79

# 6  
Old 12-01-2008
that should work fine..Thanks. Can you explain to me what the substr (d,1,4) and substr (d,5,2) do? I understand they are placing a substring of d into the name but can't figure out the number designation. Thanks!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

2. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

3. Shell Programming and Scripting

How to find empty files in a directory and write their file names in a text?

I need to find empty files in a directory and write them into a text file. Directory will contain old files as well, i need to get the empty files for the last one hour only. (1 Reply)
Discussion started by: vel4ever
1 Replies

4. Shell Programming and Scripting

Text processing of file

I have a text file which is a dataset. and I need to convert it into a CSV format The file is as follows : First line : -1 3:1 11:1 14:1 19:1 39:1 42:1 55:1 64:1 67:1 73:1 75:1 76:1 80:1 83:1 Second line " +1 5:1 11:1 15:1 32:1 39:1 40:1 52:1 63:1 67:1 73:1 74:1 76:1 78:1 83:1 There are a... (6 Replies)
Discussion started by: ajayram
6 Replies

5. Shell Programming and Scripting

Removing files with same text but different file names

Hi All, I have some 50,000 HTML files in a directory. The problem is; some HTML files are duplicate versions that is wget crawled them two times and gave them file names by appending 1, 2, 3 etc after each crawl. For example, if the file index.html has been crawled several times, it has been... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

6. Shell Programming and Scripting

How to remove common file names from text files

I'm running on freebsd -- with a default shell of csh. I have two files named A and B. Each line of each file contains a file name. How can I write a script that removes all the file names in file B from A. I tried to use perl to create a huge regular expression with "|" separating the file... (2 Replies)
Discussion started by: siegfried
2 Replies

7. Shell Programming and Scripting

matching names in 2 text files

I have 2 text files like ________________________________ Company Name:yada yada ADDRESS:some where, CITY,STATE CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3 LEAD:first_name.last_name ________________________________ & Data file2 ... (1 Reply)
Discussion started by: rider29
1 Replies

8. Shell Programming and Scripting

Extracting information from Config files /text processing

Hello All, This is my first post on this forums, which I consider one of the best of its kind. The reason for my post is that I want to export some information form Nagios configuration files to a DB. I know that there are other tools available to do this, like NDO, monarch, etc... But I want to... (3 Replies)
Discussion started by: oconmx
3 Replies

9. UNIX for Advanced & Expert Users

Processing extended ascii character file names in UNIX (BASH scipts)

Hi, I have a accentuated letter (ö) in a script for an Installer. It's a file name. This is not working and I'm told to try using the octal value for the extended ascii character. Does anyone no how to do this? If I had the word "filförval", can I just put in the value between the letters, like... (9 Replies)
Discussion started by: peli
9 Replies

10. UNIX for Dummies Questions & Answers

Processing a text file

A file contains one name per line, such as: john doe jack bruce nancy smith sam riley When I 'cat' the file, the white space is treated as a new line. For example list=`(cat /path/to/file.txt)` for items in $list do echo $items done I get: john doe (1 Reply)
Discussion started by: TheCrunge
1 Replies
Login or Register to Ask a Question