Sponsored Content
Top Forums Shell Programming and Scripting Script to loop through the files Post 302877202 by ashkul123 on Friday 29th of November 2013 12:15:38 AM
Old 11-29-2013
Script to loop through the files

Hi Experts,
Need some help regarding a requirement --

I may get any number of zipped files in a month (max 36). each of those wil contain a detail file and a header file. Also when the files arrive, there will already be previous days file lying around.

What I am trying to do is count the number of detail files and then loop through them and concatenating them (each corresponding header to deatil rec ) and then feed them to informatica one by one.

I have the below code --

Code:
i=1
while [ "$i" -lt `ls c4_ai_account[0-9][0-9]_`date +%Y%m%d`.dat | wc -w`+1 ]
do
    echo | cat c4_ai_account_[0-9]"$i"_`date +%Y%m%d`.hdr -  c4_ai_account_[0-9]"$i"_`date +%Y%m%d`.dat  > c4_account_test"$i".txt

echo "$i"
i=`expr $i + 1`
done

the file name will look like below
Code:
-rwxrwxrwx    1 l038028  users             6 Nov 18 13:35 c4_ai_account_01_20131129.dat
-rwxrwxrwx    1 l038028  users             8 Nov 18 13:35 c4_ai_account_02_20131129.dat
-rwxrwxrwx    1 l038028  users             9 Nov 18 13:35 c4_ai_customer_01_20131129.hdr
-rwxrwxrwx    1 l038028  users             9 Nov 18 13:35 c4_ai_account_01_20131129.hdr
-rwxrwxrwx    1 l038028  users             8 Nov 18 13:35 c4_ai_customer_02_20131129.hdr
-rwxrwxrwx    1 l038028  users             8 Nov 18 13:35 c4_ai_account_02_20131129.hdr
-rwxrwxrwx    1 l038028  users             7 Nov 18 13:36 c4_ai_customer_02_20131129.dat
-rwxrwxrwx    1 l038028  users            12 Nov 18 13:36 c4_ai_customer_01_20131129.dat
-rwxrwxr-x    1 l038028  users             6 Nov 29 13:38 c4_ai_account_03_20131129.dat
-rwxrwxr-x    1 l038028  users             9 Nov 29 13:39 c4_ai_account_03_20131129.hdr
-rwxrwxr-x    1 l038028  users             6 Nov 29 15:48 c4_ai_account_01_20131128.dat
-rwxrwxr-x    1 l038028  users             9 Nov 29 15:48 c4_ai_account_01_20131128.hdr

The above script is giving error -- The file c4_ai_account[0-9][0-9]_ does not exist.

Please advise on how I can achieve this. I am new to unix so any help will be greatly apprecaited.

Last edited by vbe; 11-29-2013 at 06:12 AM.. Reason: missing code hehe
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help shell script to loop through files update ctl file to be sql loaded

I am currently trying to find a way to loop through files in a given directory and for each file modify a ctl file and sql load it. I have been using the sed command to change the infile, badfile parameters of the control file. I have not yet tried to sql load it. Requirement: files are ftp to... (1 Reply)
Discussion started by: dba_nh
1 Replies

2. Shell Programming and Scripting

Script to loop through all files and directories.

I'm trying to write a script that will loop through all files and directories down from a path I give it, and change the permissions and ACL. I was able to do the obvious way and change the files and folders on the same level as teh path...but I need it to continue on deeper into the file... (2 Replies)
Discussion started by: cheetobandito
2 Replies

3. AIX

how to loop through non-empty files with shell script on AIX

I have av script that loops through some statistic files to create a report. We would like to only loop through non-empty files as these files create an empty report-line. I have figured out how to find the non-empty files, but not how to loop through only those files. Here is the code that finds... (4 Replies)
Discussion started by: Tessa
4 Replies

4. UNIX for Dummies Questions & Answers

Foreach loop to run a perl script on multiple files

Hi, I have thousands of files in a directory that have the following 2 formats: 289620178.aln 289620179.aln 289620180.aln 289620183.aln 289620184.aln 289620185.aln 289620186.aln 289620187.aln 289620188.aln 289620189.aln 289620190.aln 289620192.aln.... and: alnCDS_1.fasta (1 Reply)
Discussion started by: greptastic
1 Replies

5. UNIX for Dummies Questions & Answers

Writing a loop to manipulate a script and store it in multiple output files

I have a script where the the 9th line looks like this: $filename=sprintf("250.1chr%d.ped", $N); I want to modify this script 1000 times, changing 250.1chr%d.ped to 250.2chr%d.ped, 250.3chr%.ped.......and so on all the way to 250.1000chr%d.ped and store each output in files called ... (4 Replies)
Discussion started by: evelibertine
4 Replies

6. UNIX for Dummies Questions & Answers

Writing a loop to process multiple input files by a shell script

I have multiple input files that I want to manipulate using a shell script. The files are called 250.1 through 250.1000 but I only want the script to manipulate 250.300 through 250.1000. Before I was using the following script to manipulate the text files: for i in 250.*; do || awk... (4 Replies)
Discussion started by: evelibertine
4 Replies

7. UNIX for Dummies Questions & Answers

Using Shell Script To Loop Program Through Multiple Text Files

Hello, So I have approximately 300 files of raw data (.txt) files that I am using to perform statistical analysis. I have been able to construct a Fortran program that is able to perform my statistical analysis on a file by file basis. However, I now want to be able to loop program through... (19 Replies)
Discussion started by: Jimmyd24
19 Replies

8. Shell Programming and Scripting

Loop through multiple files in bash script

Hi Everybody, I'm a newbie to shell scripting, and I'd appreciate some help. I have a bunch of .txt files that have some unwanted content. I want to remove lines 1-3 and 1028-1098. #!/bin/bash for '*.txt' in <path to folder> do sed '1,3 d' "$f"; sed '1028,1098 d' "$f"; done I... (2 Replies)
Discussion started by: BabyNuke
2 Replies

9. UNIX for Beginners Questions & Answers

Shell script to loop through files

Hi Team, I am new to shell scripting. I have the below requirement 1) Say if i am searching for 20160815 in a directory /dir 2) Now i need to get the files present in dir whose time stamp in greater than or equal to 20160815 3) Then i need to find the string 20160815 from the set of... (3 Replies)
Discussion started by: Rajendra Kalepu
3 Replies

10. Shell Programming and Scripting

Loop Script and not opening files containing spaces

Hello, I wrote a simple script, that basically wait for a *.dat-file in a certain folder, which is always a zipped file and extracts it. It worked before and i changed nothing in the script, but since last week i have the problem, that it doesnt extract files containing a space. How do i make... (4 Replies)
Discussion started by: blend_in
4 Replies
rc.config(4)						     Kernel Interfaces Manual						      rc.config(4)

NAME
rc.config, rc.config.d - files containing system configuration information SYNOPSIS
DESCRIPTION
The system configuration used at startup is contained in files within the directory The file sources all of the files within and and exports their contents to the environment. /etc/rc.config The file is a script that sources all of the scripts, and also sources To read the configuration definitions, only this file need be sourced. This file is sourced by whenever it is run, such as when the command is run to transition between run states. Each file that exists in is sourced, without regard to which startup scripts are to be executed. /etc/rc.config.d The configuration information is structured as a directory of files, rather than as a single file containing the same information. This allows developers to create and manage their own configuration files here, without the complications of shared ownership and access of a common file. /etc/rc.config.d/* Files This is where files containing configuration variable assignments are located. Configuration scripts must be written to be read by the POSIX shell, and not the Bourne shell, or In some cases, these files must also be read and possibly modified by control scripts or the sam program. See sd(4) and sam(1M). For this reason, each variable definition must appear on a separate line, with the syntax: No trailing comments may appear on a variable definition line. Comment statements must be on separate lines, with the comment character in column one. This example shows the required syntax for configuration files: Configuration variables may be declared as array parameters when describing multiple instances of the variable configuration. For example, a system may contain two network interfaces, each having a unique IP address and subnet mask (see ifconfig(1M)). An example of such a dec- laration is as follows: Note that there must be no requirements on the order of the files sourced. This means configuration files must not refer to variables defined in other configuration files, since there is no guarantee that the variable being referenced is currently defined. There is no protection against environment variable namespace collision in these configuration files. Programmers must take care to avoid such prob- lems. /etc/TIMEZONE The file contains the definition of the environment variable. This file is required by POSIX. It is sourced by at the same time the files are sourced. SEE ALSO
rc(1M). rc.config(4)
All times are GMT -4. The time now is 10:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy