Wildcards in file input to a script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wildcards in file input to a script?
# 8  
Old 11-09-2012
I don't understand your question.
# 9  
Old 11-09-2012
Quote:
Originally Posted by Scott
I don't understand your question.
Sorry, that could be described a bit better, yes.

What if I would want to do this in a script:

grep string file*

This would obviously not work then, as it would only grep in one file?
Code:
#!/bin/bash
grep $1 $2

# 10  
Old 11-09-2012
grep string file* would work (assuming "file*" doesn't expand to too many files).

If you want to do this from the command line, then:
Code:
$ ./myScript "some string to search for" file*

$ cat myScript
STR=$1
shift
grep "$STR" "$@"

This User Gave Thanks to Scott For This Post:
# 11  
Old 11-09-2012
Quote:
Originally Posted by Scott
grep string file* would work (assuming "file*" doesn't expand to too many files).

If you want to do this from the command line, then:
Code:
$ ./myScript "some string to search for" file*

$ cat myScript
STR=$1
shift
grep "$STR" "$@"

Thanks, that works like a charm. Smilie What does shift do?
# 12  
Old 11-09-2012
shift = move along, nothing to see here Smilie

Code:
$ cat myScript
echo $1 $2 $3
shift # get rid of first argument ($1)
echo $1 $2 $3

$ ./myScript A B C
A B C
B C

# 13  
Old 11-09-2012
Quote:
Originally Posted by Scott
shift = move along, nothing to see here Smilie

Code:
$ cat myScript
echo $1 $2 $3
shift # get rid of first argument ($1)
echo $1 $2 $3

$ ./myScript A B C
A B C
B C

Ah, nice. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

2. Shell Programming and Scripting

SH Script for file name wildcards

Does anyone know how I would go about inserting text at the beginning of a file with the file name containing a daily time stamp? Essentially I need to find the file name using a wild card, and then insert 3 lines of text - one of which is the processing date. Help please!? (1 Reply)
Discussion started by: cookie33
1 Replies

3. Shell Programming and Scripting

AWK Script to convert input file(s) to output file

Hi All, I am hoping someone can help me with some scripting I need to complete using AWK. I'm trying to process multiple fixed files to generate one concatenated fixed file in a standard format. The Input file is:- aaaa bbbbb ccccc 1 xxxx aaa bbb aaaa bbbbb ccccc 2 abcd aaa CCC... (9 Replies)
Discussion started by: jason_v_brown
9 Replies

4. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

5. Shell Programming and Scripting

Check for file existence using wildcards

I am using the following command to check for files on a Unix (Solaris 9) and on Linux: if (-r *.) then echo " las file found" else echo " no las file found" endif If no las file is present, the "no las file found" message is displayed. If a las file is present, however, I get... (9 Replies)
Discussion started by: phudgens
9 Replies

6. UNIX for Dummies Questions & Answers

Running script on SFTP server, RMDIR and RM with wildcards

Im going insane trying to figure out what i consider a basic command on an SFTP server... Im trying to download all files from a directory *done* then remove all the files (and sometimes folders that contain files) i have downloaded on the remote directory... the command i would normally... (2 Replies)
Discussion started by: mokachoka
2 Replies

7. Shell Programming and Scripting

Perl script to search and extract using wildcards.

Good evening All, I have a perl script to pull out all occurrences of a files beginning with xx and ending in .p. I will then loop through all 1K files in a directory. I can grep for xx*.p files but it gives me the entire line. I wish to output to a single colum with only the hits found. ... (3 Replies)
Discussion started by: CammyD
3 Replies

8. Shell Programming and Scripting

How to chk the file name using wildcards??

Hi, I need to find a file with name xyz.mno.1234235.msg Here the numbers can be anything and is not fixed. But the first 6 characters are fixed ie, xyz and mno are fixed and wont change. Actually this file comes to this directory every week with only the number part changing. How is it... (7 Replies)
Discussion started by: RRVARMA
7 Replies

9. Shell Programming and Scripting

Use wildcards in a script

Hello I have this script: #!/bin/ksh INPUTFILE=$1 TEMPFILE=$INPUTFILE.$$ OUTPUTFILE=$INPUTFILE.new # nr of arguments has to be 1 if then echo "\nUsage: $0 inputfile\n" return 1 fi # inputfile must exist and be readable if then (13 Replies)
Discussion started by: emferrari
13 Replies

10. UNIX for Dummies Questions & Answers

script for deletion using wildcards

find ./ -name t\* | sed "s@^./@@" > .filestobedeleted j=$(wc -l < .filestobedeleted) typeset -i cnt=0 typeset -i i=0 while read line do myarray=$line ((cnt = cnt + 1)) done < .filestobedeleted while (1 Reply)
Discussion started by: aishu
1 Replies
Login or Register to Ask a Question