Compare file names and select correct elements to include in "for each loop"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare file names and select correct elements to include in "for each loop"
# 1  
Old 11-04-2010
Compare file names and select correct elements to include in "for each loop"

Hi everyone,

I`ll try to be most clear I can explaining my help request.

I have 2 folders
Folder A-->This folder receives files through FTP constantly
Folder B-->The files from Folder A are unzipped and then processed in Folder B

Sometimes Folder A doesn`t contain all corresponding/relatives files in Folder B,
I mean, in certain moment only a new Computers.gz and a new Scanners.gz are present
in Folder A and the other *.gz are not present, these correspond with Computers_Processed.txt and Scanners_Processed.txt.
in Folder B. Something as follow:

Folder A Folder B
--------------------------------------------  
Cellphones_Processed.txt
Computers.gz Computers_Processed.txt
Printers_Processed.txt
Scanners.gz Scanners_Processed.txt
I have a long AWK routine (let say routine B) to process all text files (*.txt) in Folder B independently which
files are present in Folder A. something like this

#++ Routine B ++#

Code:
for each in *.txt;  # Runs on every file in Folder B
do
{AWK routine...}
done

I would like to have a routine (let say routine A) that detects which filename.gz is present
in Folder A in a given moment and say over which filename_Processed.txt execute AWK routine.

I mean, routine A will get the list of elements for the selective "for each" loop.

Folder A Folder B Routine A Says
--------------------------------------------------------------------------------------   
Cellphones_Processed.txt
Computers.gz Computers_Processed.txt Execute AWK routine on this file
Printers_Processed.txt
Scanners.gz Scanners_Processed.txt Execute AWK routine on this file either
# for this example elegible elements to fill the list are Computers_Processed.txt and Scanners_Processed.txt

#++ Routine A++# I imagine would be
something like this:
Code:
for each in {Computers_Processed.txt Scanners_Processed.txt}; 
do
{AWK Routine...}
done

Then, comparing the name of files in folder A and B,
how to get the correct list of elements to include in the "for each" statement?

Thanks in advance for any help
# 2  
Old 11-04-2010
Code:
LIST=$(ls FolderA | sed 's/\.gz/_Processed.txt/')
for each in $LIST
...


Last edited by ctsgnb; 11-04-2010 at 09:23 AM..
# 3  
Old 11-04-2010
Hi ctsgnb,

It looks is easiest than I was thinking Smilie.

I`ll give a try with this.

Thank you so much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Compare Only "File Names" in 2 Files with file lists having different directory structure

I have a tar arcive arch_all.tar.gz and 4 batched tar archive . These batches are supposed to have all the files form arch1.all.tar.gz arch1_batch1.tar.gz arch1_batch2.tar.gz arch1_batch3.tar.gz arch1_batch4.tar.gz my issue is that the directory structure in "arch_all.tar.gz" is... (6 Replies)
Discussion started by: sumang24
6 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Emergency UNIX and Linux Support

Accidentally Changed File Ownership to Include a "Comment" [AIX]

Hi. I've had a little mishap. To cut a long story short, I've accidentally recursively ran chown on a directory (actually a bunch of 'em). Not a problem in itself, but I had a slight error in the code I used to get the list of directories and ended up with a comment in the file ownership. ... (15 Replies)
Discussion started by: Scott
15 Replies

5. UNIX for Dummies Questions & Answers

File name select to "clipboard"

I want to be able to take a file name and then use sedto paste that text into the file. I believe I know how to do the latter portion of pasting into the file at the location I want, but I do not know how to "copy" the file name to the "clipboard" for pasting. Ideally I want to be able to... (1 Reply)
Discussion started by: TitanTlaloc
1 Replies

6. Shell Programming and Scripting

The "read" command misinterprets file names containing spaces

The "read" command, which is built into bash, takes words from the standard input. However, "read" is not good at taking file names if the file names contain spaces. I would like my bash script to ask the user to enter file names, which may contain spaces. Can you think about any technique for... (14 Replies)
Discussion started by: LessNux
14 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

perl file, one line code include "length, rindex, substr", slow

Hi Everyone, # cat a.txt a;b;c;64O a;b;c;d;ee;f # cat a.pl #!/usr/bin/perl use strict; use warnings; my $tmp3 = ",,a,,b,,c,,d,,e,,f,,"; open(my $FA, "a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\;/, $_); if ( ($tmp =~ m/^(64O)/i) || ($tmp... (3 Replies)
Discussion started by: jimmy_y
3 Replies

9. Shell Programming and Scripting

Why stderr file descriptor redirection makes ksh's "select" construct hang.

I am trying to use one global declaration --> "exec 2>$ERR" to capture all stderr outputs that may occur anywhere in my script. Then close it at the end of the script using --> "exec 2<&-" I am using KSH on Solaris 8. KSH Version M-11/16/88i If I comment two "exec .." statements in the... (11 Replies)
Discussion started by: kchinnam
11 Replies

10. UNIX for Dummies Questions & Answers

File names that contain "01" act hidden

Haveing an issue. Anytime a file is created with "01" (zero one) in the name - it cannot be viewed by LS or any other file listing command. Although the file is there, it cannot be seen. I can edit it, run it, anything, except see it..... What happened? Any ideas? (8 Replies)
Discussion started by: n9ninchd
8 Replies
Login or Register to Ask a Question