Home » Infrastructure » Linux » Shell Script for grepping
Shell Script for grepping [message #98861] Sat, 17 May 2003 15:07 Go to next message
Ced
Messages: 1
Registered: May 2003
Junior Member
I just started learning to write shell scripts a couple of days ago and I'm trying to work a glitch out of a script I've been using to find a string, sort it a particular way, and then save it to a text file. the script looks like this:

#!/bin/sh
Grep -in "whatever" filename.tex | sort -bdf | tee greppedtext.txt

This script works fine as long as I name the specific file to be grepped within the script. However, I want to make the file I'm grepping a *variable* so I can determine what it will be from the command line like this:

$ubergrep "whatever" anyfile_in_directory.tex

How do I make the file to be grepped a variable in the script? I've looked all over my "Unix Power Tools" and the web for solutions. I would be very appreciative of anyone who could help me with this problem. Thank you!
Re: Shell Script for grepping [message #98900 is a reply to message #98861] Mon, 14 July 2003 16:35 Go to previous message
LKBrwn_DBA
Messages: 487
Registered: July 2003
Location: WPB, FL
Senior Member
Try this:

#!/bin/sh
grep -in "$1" $2 | sort -bdf | tee greppedtext.txt

And execute like:

ubergrep "whatever" anyfile_in_directory.txt
Previous Topic: oracle9i on Linux - Please help
Next Topic: Linux8.0/Oracle8i 8.1.7.x Error :TNS: LOST CONTACT
Goto Forum:
  


Current Time: Thu Apr 18 21:20:50 CDT 2024