Sponsored Content
Top Forums Shell Programming and Scripting Simple Script looking for Hard Coded Variables Post 302336214 by kshji on Tuesday 21st of July 2009 02:16:35 PM
Old 07-21-2009
You don't need eval, 1 parse is enough.
Code:
#!/usr/bin/ksh
#simple script to grep for the IP of the host in any file
echo -n "Enter the IP address you want to find:"
read IP
log=/tmp/ipfind.out.$IP
echo "greping all files for $IP"
echo "This will take a considerable amount of time to complete..."
echo "Scripts logs to /tmp/ipfind.out.$IP"
# IP include ., which is special char for regexp, so you need change . -> \.
IP="${IP//./\\.}" 
# find regular files and grep IP, take time, output only filenames which include $IP
find / -type f -exec grep -l "$IP" {} \;  > $log  2>/dev/null
echo "Script complete. please check $log"

 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Get enviroment variables into AWK, but not quite that simple!

Hi, I have a script which loops through a file and based on the fields in the file does certain things. I'm just testing the final version and come up against a problem. One of the things is to copy files, so the line in the release.file would look like this. COPY my_file $COPY_DIR 777 ... (1 Reply)
Discussion started by: m1l
1 Replies

2. Shell Programming and Scripting

Simple question (for you guys, hard for me)

I am trying to exit this script by cd'ing into a particular directory. #!/bin/bash /opt/xxx/xxx/d2h $1 fname=$( /opt/xxx/xxx/d2h $1) cd /opt/xxx1/xxx1 find . -name '*'$fname'*' -ls cd /opt/xxx1/xxx1 Upon execution, it returns to my home directory (where I am running this script from. ... (3 Replies)
Discussion started by: BkontheShell718
3 Replies

3. Shell Programming and Scripting

Simple unix variables in script

I'm creating a script that asks a user for a variable ex read filename; read numberinput; I also have a bunch of files named file.0 file.1 ... file.55 I'm trying to delete all files (if they exist) about file.$numberinput. Can someone help me out on how to include the variable as part... (6 Replies)
Discussion started by: jenix4545
6 Replies

4. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

5. UNIX for Dummies Questions & Answers

Simple example for soft and hard links

Hai, give me a simple example for soft and hard links. this will work for soft link ?? ln -s (2 Replies)
Discussion started by: Ramesh M
2 Replies

6. Programming

How to select option for binary coded value?

Hello everybody, I looking for advice. I'm trying to decode a binary file. Some parameters are "Binary coded", that means that if a byte in hexadecimal is "0A", then in binary is 00001010. So, to decode this Byte I need to refer to the table below (depending the value in binary format, the... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

7. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

8. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 02:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy