How to Process input files from folder in shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Process input files from folder in shell script?
# 1  
Old 10-01-2010
How to Process input files from folder in shell script?

Hi,

I want to process all input files available into folder (C:\ShellPrg\InputFile\) Input files are abc.CSV , XYZ.zip (zip of CSV file), PQR.gz (zip of CSV file).

I want to check the extension of file, If its .zip/.gz then need to unzip the file as .CSV
I want to parse line by line of each .CSV file.

Here is my code,
Code:
FILE=$1
echo $FILE
EXTN=`echo $FILE | cut -d "." -f 2`
 
if [ $EXTN == "zip" ]; then
    input_file=`unzip $FILE`
    echo "input file is $input_file"
elif [ $EXTN == "gz" ]; then
    input_file=`gzip -d $FILE`
fi
EXTN1=`echo $input_file | cut -d "." -f 2`
if [ $EXTN1 == "CSV" ]; then
    // code of line parse
fi

where $1 = <PATH> a_b_c_d_1234.CSV / a_b_c_d_1234.zip / a_b_c_d_1234.gz

How can I put the for loop to process each file from folder?
Also help me to unzip the file and store the unzipped file name into a variable?

Moderator's Comments:
Mod Comment Time to start using code tags.
# 2  
Old 10-01-2010
Code:
for FILE in *; do
echo $FILE
EXTN=`echo $FILE | cut -d "." -f 2`
 
if [ $EXTN == "zip" ]; then
    input_file=`unzip $FILE`
    echo "input file is $input_file"
elif [ $EXTN == "gz" ]; then
    input_file=`gzip -d $FILE`
fi
EXTN1=`echo $input_file | cut -d "." -f 2`
if [ $EXTN1 == "CSV" ]; then
    // code of line parse
fi
done

# 3  
Old 10-01-2010
OK.
Help me to unzip the file and store the unzipped file name into a variable.
From my code i am getting output as,

Code:
input file is Archive:  a_b_c_d_1234.zip

Thanks in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to execute 10 sql files from a folder through sqlplus in shell script?

I am new to shell scripting and i want to know how to execute the *.sql files from a folder through sqlplus in shell script and files should be execute in sequentially one by one while execution if any ORA error it has to exit from sqlplus session 1) scripts from external folder 2) logs has... (1 Reply)
Discussion started by: sreekanth Reddy
1 Replies

2. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

3. Shell Programming and Scripting

Shell script to copy files from on folder to another

I am trying to copy files with specific date and name to another folder. I am very new to shell scripting so i am finding it hard to do that. see the sample code i have written below. srcdir="/media/ubuntu/CA52057F5205720D/Users/st4r8_000/Desktop/office work/26 nov"... (13 Replies)
Discussion started by: Aqeel Abbas
13 Replies

4. Shell Programming and Scripting

Shell script that lists files with different owner than the folder

Hello, I'm trying to write a script which is listing files based on different preferences, like filetype or permissions. All is fine, except for one: I want to list files in /home which has a different owner than the home directory it is in. Here is an example: /home/UserA is the directory, and... (10 Replies)
Discussion started by: Zwiebi
10 Replies

5. 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

6. Shell Programming and Scripting

How to process multiple input files using Shell scripting

Hi, I would like to write a for loop that does the following: I have a file called X.txt and other files called 1.txt,2.txt, .....,1000.txt. I want to substitute the 6th column of the file X.txt with 1.txt and store the output as X.1. Then I want to do the same with X.txt and 2.txt and store... (0 Replies)
Discussion started by: evelibertine
0 Replies

7. Shell Programming and Scripting

How to unzip files from folder in shell script (ksh)?

I have a folder (C:\shellprg\input\) containing .CSV, .zip, .gz files. 1] I want to find all .zip/.gz files from folder (C:\shellprg\input\). 2] unzip/uncompress files into the same folder (C:\shellprg\input\) through shell script. I am using below commands for unzip files, unzip <filename>... (2 Replies)
Discussion started by: Poonamol
2 Replies

8. Shell Programming and Scripting

Shell Script to monitor folder and upload found files via FTP

Hi everyone! I'm in a need of a shell script that search for all files in a folder, move all those files to a temp folder, and upload those files via FTP. When the file transfer via FTP completes successfully, the file is moved to a completed folder. In case any of those files fails, the file... (4 Replies)
Discussion started by: pulsorock
4 Replies

9. Shell Programming and Scripting

HOW TO CHECK ONLY .C FILES EXISTS OR NOT IN A FOLDER using IF in C shell script?

Hi friends.. I hav a problem.... I dont know how to check .c files exists r not in a folder using IF in C shell script actually i tried like this if(=~ *.c) even though some .c files or there in the current folder..it is not entering int o the if control statement...... (17 Replies)
Discussion started by: p.hemadrireddy
17 Replies

10. Shell Programming and Scripting

Shell script to find out 2 last modified files in a folder..PLZ HELP!!!!!!!!!

hi all, I need to find out the last 2 modified files in a folder.There is some way by which,we can check the timestamp and find out..??please help this is urgent. Thanks in Advance Anju (3 Replies)
Discussion started by: anju
3 Replies
Login or Register to Ask a Question