Input for multiple files.


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Input for multiple files.
# 1  
Old 04-28-2011
Input for multiple files.

Hi,

I am trying to come up with a script, and would like the script to pick all the files place within a folder and interactive take my yes/no before processing within the command. Could you someone help me in modifying the script :


Code:
#!/bin/bash
#
LDIF_FILES="File Name"
 
for MY_FILE in $LDIF_FILES
do
command -D <USER_FOR_BIND> -j <PASSWORD_FILE> -c -v -a -f $MY_FILE -e $MY_FILE.err
done

Thanks, John
# 2  
Old 04-28-2011
I have put in 3 strings as example for the file names. The command has been put into an extra function do_it() outside to be more flexible and not have to write too much text inside the case/esac.
I placed an echo and double quotation marks around the command, so you can test without actually executing that command.

Code:
#!/bin/bash
#
LDIF_FILES="file1 file2 file3"

do_it()
{
        MY_FILE=$1
        echo "command -D <USER_FOR_BIND> -j <PASSWORD_FILE> -c -v -a -f $MY_FILE -e $MY_FILE.err"
}

for MY_FILE in $LDIF_FILES
do
        echo "Process file [${MY_FILE}]? Enter [y|n]"
        read INPUT
        case $INPUT in
                [yY])   do_it $MY_FILE ;;
                [nN])   continue ;;
                *)              echo "Only y or n allowed."
        esac
done

exit 0

If you need to fill the LDIF_FILES with some life, you could do something like
Code:
...
LDIF_FILES=$(ls -1 *.ldif)
...

or something appropriate. Maybe add a -R for recursiveness or a find if your ls does not support -R ... or a for loop.
# 3  
Old 04-29-2011
Hi,

Thank you for the update. I am trying to run, it is giving me syntax for the following line :

Code:
*)              echo "Only y or n allowed."

- John
# 4  
Old 05-02-2011
Hi,

can someone else help me with the script?

John
# 5  
Old 05-02-2011
Hi, just add ;; a the end of the line with error.
This User Gave Thanks to Chirel For This Post:
# 6  
Old 05-03-2011
Thanks this is working! .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Multiple input files and output files

Hi, I have many test*.ft1 files to which I want to read as input for a script called pipe2txt.tcl and print the output in each separate file. For example, pipe2txt.tcl < test001.ft1 > test001.txt How can I read many files in this maner? thank you very much, Best, Pahuja (5 Replies)
Discussion started by: Pahuja
5 Replies

2. Shell Programming and Scripting

FOR loop with multiple files as input and awk

Hi all , i want to pass multiple files as input to a for loop for i in file1 file2 file3 do some awk action < $i >> $i.out done but im getting error in that for loop is the way i use to pass files to awk using for correct and 2.we can directly pass multiple files to awk as... (7 Replies)
Discussion started by: zozoo
7 Replies

3. Shell Programming and Scripting

awk, multiple files input and multiple files output

Hi! I'm new in awk and I need some help. I have a folder with a lot of files and I need that awk do something in each file and print a new file with the output. The input file name should be modified when I print the outpu files. Thanks in advance for help! :-) ciao (5 Replies)
Discussion started by: gabrysfe
5 Replies

4. UNIX for Dummies Questions & Answers

Writing a for loop that processes multiple input files

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 the... (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

how to give multiple csv files as input in awk

Hi All, I am new to shell scripting..My problem is i want to give multiple csv files as input to awk script and process the data into one file.. My input file is File1 File2 File3 Product Location Period SalesPrice A x 8/11/2010 ... (7 Replies)
Discussion started by: kvth
7 Replies

6. Shell Programming and Scripting

SED command using multiple input files

What is the syntax to use multiple input files in a SED command. i.e. substitute a word with a phrase in every file in a directory. for every file in /usr/include that has the word "date" in the file grep -l '\<date\>' /usr/include/*.h find each occurrence of the word "time" in the file &... (3 Replies)
Discussion started by: sheoguey
3 Replies

7. Shell Programming and Scripting

How to get this script work on multiple input files

Hello Gyues! I would like to use awk to perform data extraction from several files. The data files look like this: DWT26R 1 PEP1 CA 1 OH2 SKIPPED: 0 STEP: 1 0.29000E+01 0.55005E-02 0.60012E-03 0.30000E+01 0.11149E+00 0.13603E-01 0.31000E+01 0.39719E+00 0.63013E-01 0.32000E+01... (9 Replies)
Discussion started by: Daniel8472
9 Replies

8. Shell Programming and Scripting

how to redirect multiple input files?

I have a program that runs like "cat f1 - f2 -", I need to write shell script to run the program whose standard input will be redirected from 2 files. I spend a whole day on it, but didn't figure out. Can someone help me out? Thanks! (8 Replies)
Discussion started by: microstarwwx
8 Replies

9. Shell Programming and Scripting

Splitting input files into multiple files through AWK command

Hi, I needs to split *.txt files from single directory depends on the some mutltiple input values. i have wrote the code like below for file in *.txt do grep -i -h "value1|value2" $file > $file; done. My requirment is more input values needs to be given in grep; let us say 50... (3 Replies)
Discussion started by: arund_01
3 Replies

10. UNIX for Dummies Questions & Answers

can you redirect multiple files for input?

I have a program that is reading strings into a vector from a file. Currently I am using this command: a.out < file1 The program runs and prints the contents of the vector to the screen, like its supposed to. The problem is that it needs to read in 3 files to fill the vector. Is there anyway... (4 Replies)
Discussion started by: Matrix_Prime
4 Replies
Login or Register to Ask a Question