How to process multiple files in Korn Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to process multiple files in Korn Shell
# 1  
Old 11-22-2005
Question How to process multiple files in Korn Shell

How do I make the below ksh to process all of the files inside a user specified directory?
Currently it can only process one file at a time.

#!/bin/ksh

tr -s '\11 ' ' ' < $1 > temp0

sed -e 's/,//g' temp0 > temp1

cut -d' ' -f1,4,5 temp1 > final_output

rm temp0 temp1
# 2  
Old 11-22-2005
This should work

Code:
for file in /dir/to/process/*
do
tr -s '\11 ' ' ' < $file > temp0
sed -e 's/,//g' temp0 > temp1 
cut -d' ' -f1,4,5 temp1 >> final_output
rm temp0 temp1
done

This User Gave Thanks to vino For This Post:
# 3  
Old 11-22-2005
Thank you Vino!
It worked.
# 4  
Old 11-22-2005
Quote:
Originally Posted by vino
This should work

Code:
for file in /dir/to/process/*
do
tr -s '\11 ' ' ' < $file > temp0
sed -e 's/,//g' temp0 > temp1 
cut -d' ' -f1,4,5 temp1 >> final_output
rm temp0 temp1
done


You really dont need "rm temp0 temp1" in the loop. You can use rm outside the loop.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

3. Shell Programming and Scripting

korn shell remove files question

how do you show each filename in a giving directory and delete the specific file in korn script i was thinking using ls rm ? but i cant make it work (0 Replies)
Discussion started by: babuda0059
0 Replies

4. UNIX for Dummies Questions & Answers

Initializing files to empty in korn shell

hello, i want to know how to initialize a file to an empty one in korn shell scripting? i'm using a file name and building it during a while loop using >>. The problem occurs when the file is not empty before reaching the while loop. therefore, i want to initialize it before the loop to get... (6 Replies)
Discussion started by: alrinno
6 Replies

5. UNIX for Dummies Questions & Answers

Korn shell awk use for updating two files

Hi, I have two text files containing records in following format: file1 format is: name1 age1 nickname1 path1 name2 age2 nickname2 path2 file 1 example is: abcd 13 abcd.13 /home/temp/abcd.13 efgh 15 efgh.15 /home/temp/new/efgh.15 (4 Replies)
Discussion started by: alrinno
4 Replies

6. UNIX for Dummies Questions & Answers

find and FTP multiple files in Korn Shell

I want to FTP multiple files in a directory that the files were created since midnight of the same day using korn shell. I can use the "find" command using -newer arguement that compares against a time stamp file. The script identifies the files, I can't use a variable = `find . ` as the... (2 Replies)
Discussion started by: lambjam
2 Replies

7. Shell Programming and Scripting

Run a process through inetd using korn shell!!!

Hi, I am trying to run a process through inetd using ksh. The entry in /etc/inetd.conf is Process_Name tcp nowait root /home/user/script script The script is as follows /usr/bin/ksh -c /path/process Recycling inetd services is successfully completed. But when the process is accessed... (8 Replies)
Discussion started by: vishi_82
8 Replies

8. UNIX for Dummies Questions & Answers

Lookup between 2 files ( korn shell )

Hi All., i have a problem. I hope i can get some help on this issue here; i have 2 txt files say file1 and file 2 file1 has; WLMT:XXXXXXXX:cp DOLR:YYYYYYY:ascii,unblock WLG:TTTTTTT:dd:73:ascii,unblock MAR:SSSSSS:dd:152:ascii,unblock GGG:QQQQQQQQQQ:112:ascii,unblock EIE:CCCCCCCC:cp... (17 Replies)
Discussion started by: pavan_test
17 Replies

9. Shell Programming and Scripting

korn shell + sftp + list files

Hello!!! I need a korn shell script in AIX that inside sftp environment, changes a remote directory, lists the files inside it, and stores in an array. I got it working before make a sftp, but after.. I can't.. The way it is, it lists the files in local path... so.. not what I want, but... (1 Reply)
Discussion started by: alienET
1 Replies

10. Shell Programming and Scripting

Multiple su - in Korn Shell script

i am trying to do something like this : #!/bin/ksh # Change to the userid user1 su - user1 #Issue the command to change directory and list files cd /home/user1/ ls -lrt exit #Come out of the user1 to root again #change to user 2 su - user2 cd /home/user2/ ls -lrt... (2 Replies)
Discussion started by: furrari
2 Replies
Login or Register to Ask a Question