Accepting search pattern to script argument


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Accepting search pattern to script argument
# 1  
Old 02-21-2012
Accepting search pattern to script argument

I have a script in tcsh and I want to have a find option to which I can pass a file search pattern I want using the command:

Code:
 /home/chrisd/tatsh/trunk/hstmy/bin/tcsh/raytrac.tcsh -f=*rc*

The set command seems to fail when user does not supply a search pattern (if user just supplies -f, a default search is performed).

Code:
 /home/chrisd/tatsh/trunk/hstmy/bin/tcsh/raytrac.tcsh -f


E.g. of the code:

Code:
/home/chrisd/tatsh/trunk/hstmy/bin/tcsh/raytrac.tcsh -f=*rc*

This is failing. I just want to get the *rc*
Code:
set arg_ierrLst = ""
set narg = $#argv
while ($iarg < $narg)

  MATH iarg = $iarg + 1
  set arg = $argv[$iarg]
  set opt = `echo $arg | awk 'BEGIN {FS="="} {print $1}' | tr '[:lower:]' '[:upper:]'`
  set par = `echo $arg | awk 'BEGIN {FS="="} {print $2}'`

  switch ($opt)

  case "-F":
  case "--FIND":
    set arg_findPtn = $par
    set opt_find = 1
    breaksw

  default:
    set arg_ierrLst = "$arg_ierrLst $arg"
    set ierr = 1
    breaksw

  endsw

end   # which


Last edited by kristinu; 02-21-2012 at 07:01 AM..
# 2  
Old 02-21-2012
ok i'm tcsh ignorant. forgive this post.
# 3  
Old 02-21-2012
I have written

Code:
set varq = "'$1'"
echo "varq = $varq"
set opt = `echo $varq | awk 'BEGIN {FS="="} {print $1}' | tr '[:lower:]' '[:upper:]'`
set par = `echo $varq | awk 'BEGIN {FS="="} {print $2}'`
echo "opt = $opt, par = $par"

Using the above piece of code and calling the program using:
Code:
/home/chrisd/tatsh/trunk/hstmy/bin/tcsh/test.tcsh '-f=*.com'

gives

Code:
varq = '-f=*.com'
echo: No match.
echo: No match.
opt = , par =

Seems echo is not liking it. Using cat instead of echo still gives same problem.

I have now tried

Code:
set arg = "'$argv[1]'"
set opt = `echo "$arg" | awk 'BEGIN {FS="="} {print $1}'`
set par = `echo "$arg" | awk 'BEGIN {FS="="} {print $2}'`
echo "arg = $arg, opt = $opt, par = $par"

and am getting

Code:
arg = '-f=*.com', opt = '-F, par = *.com'

Seems things are progressing now

The question I have now is how to remove the ' from arg.

I have tried
Code:
set arg = `echo "$arg" | tr '\'' ''`
 set arg = `echo "$arg" | awk '{gsub(/\'/,"")}; {print}'`

but neither of them worked.

Last edited by kristinu; 02-21-2012 at 01:47 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. UNIX for Beginners Questions & Answers

Using forward slash in search pattern in perl script

I have existing pattern in the perl script as: my $pattern = "^Line.*?:|^Errors*: |^SEVERE:.*?:|^Null pointer exception occurred"; and I wanted to include below keywords in my search pattern "I/O exception" and "FileNotFoundException"the problem is when I include my pattern like my... (5 Replies)
Discussion started by: ambarginni
5 Replies

3. Shell Programming and Scripting

UNIX Shell Script Help for pattern search

Hi Need help for below coding scenario. I have a file with say 4 lines as below. DEFINE JOB TPT_LOAD_INTO_EMP_DET ( TDPID = @TPT_TDSERVER , USERNAME = @TPT_TDUSER ) ; ( 'DROP TABLE '||@TPT_WRKDB ||'.LOG_'||@TPT_TGT ||' ; ') , SELECT * FROM OPERATOR (FILE_READER) ; ) ; Now I want to... (5 Replies)
Discussion started by: Santanu2015
5 Replies

4. Shell Programming and Scripting

perl script to search n place a pattern

hi, i have one file as t1.txt as below hi hello welcome i want perl script to search for the pattern "abcd" in the file. if the pattern doesn't exist, i want to insert that pattern at the end of the same file t1.txt my o/p should be hi hllo welcome abcd thank you (3 Replies)
Discussion started by: roopa
3 Replies

5. Shell Programming and Scripting

Help with Accepting Directories as an Argument

I'm doing a script where you are suppose to start off in accepting one or more directory as an argument. How do i do this? Sorry for the nub question. (2 Replies)
Discussion started by: LinuxUser232331
2 Replies

6. Shell Programming and Scripting

How to pass multiple file types search pattern as argument to find?

How can I pass $var_find variable as argment to find command? test.sh var_find=' \( -name "*.xml" -o -name "*.jsp" \) ' echo "${var_find}" find . -type f ${var_find} -print # Below statement works fine.. I want to replace this with the above.. #find . \( -name "*.xml" -o -name... (4 Replies)
Discussion started by: kchinnam
4 Replies

7. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

8. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

9. Shell Programming and Scripting

Not able to display the value I am accepting as an argument

Hi, I am new to UNIX. I am facing some problem here. #! /usr/bin/ksh currDate = $1 export currDate; echo " Date is $currDate" when I run this script, it says : currDate not found. Can anybody point out the mistake please. --mahek (3 Replies)
Discussion started by: mahek_bedi
3 Replies

10. Shell Programming and Scripting

File search for pattern - script

Hi All, I have two directories as 1) mi/job -> job1.sh, job2.sh, job3.sh 2) mi/sysin -> sysin1, sysin2, sysin3,sysin4 I want to wrrite a script such that it should accept two parameters as directory paths. $ myscript mi/sysin mi/job. The script should be able to scan all files... (3 Replies)
Discussion started by: rahulrathod
3 Replies
Login or Register to Ask a Question