create file as variable for searching point


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting create file as variable for searching point
# 1  
Old 07-03-2010
create file as variable for searching point

Hi Friends,

I need expert helpSmilie,

I have bellow script that function for searching string in multiple file,
the script is working well.
but I thing it still can be optimize since so many repetition in bellow command, where string that I marked BOLD italic is clue for what I am looking for

Code:
gzcat  radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz |  /tmp/find_ses.pl "510098810513720" >> temp/opera.log

is it possible to put clue in different file that the script refer to ?

the content of clue file only string that I want looking for :
Code:
 510098810513720
 510098810127652
 510098810129898
 etc
 etc

another question is =
2010062[0123456] to match date 20100620 until 20100626
how to match last 2 digit example from date 20100615 until 20100626
where 15-26 is variable


here is the full script

Code:
#!/bin/bash
array1=(12 58)
array2=(00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23)
for (( x=0; x<2; x++ )); do
for (( y=0; y<24; y++ )); do
        gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "510098810513720" >> temp/opera.log
        gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "510098810127652" >> temp/opera.log
        gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "510098810129898" >> temp/opera.log
        gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "510098810457113" >> temp/opera.log
        gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "510098810133736" >> temp/opera.log
        gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "510098811104417" >> temp/opera.log
        gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "510098810198601" >> temp/opera.log
        gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "510098811012483" >> temp/opera.log
        gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "510098810389153" >> temp/opera.log
        gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "510098810473130" >> temp/opera.log
done
done


Last edited by Scott; 07-03-2010 at 07:49 AM.. Reason: Please use code tags
# 2  
Old 07-03-2010
put patterns in a file (/tmp/patterns.txt)
Code:
$ echo "$(</tmp/patterns.txt)"
510098810513720
510098810127652
510098810129898
510098810457113
510098810133736
510098811104417
510098810198601
510098811012483
510098810389153
510098810473130

Code:
#!/bin/bash
array1=(12 58)
array2=(00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23)
while read pattern; do
   for (( x=0; x<2; x++ )); do
      for (( y=0; y<24; y++ )); do
         gzcat radacct/10.17.3.${array1[$x]}/detail-2010062[0123456]_${array2[$y]}.gz | /tmp/find_ses.pl "$pattern" >> temp/opera.log
      done
   done
done < /tmp/patterns.txt

This User Gave Thanks to daPeach For This Post:
# 3  
Old 07-03-2010
MySQL Thanks

Hi daPeach,

The script is working great exactly as I want.

thank you very much.

maybe you or other can answer my second question ?

2010062[0123456] to match date 20100620 until 20100626
how to match last 2 digit example from date 20100615 until 20100626
where 15-26 is variable
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Can we create any check-point feature in shell ?

I have a script as below and say its failed @ function fs_ck {} then it should exit and next time i execute it it should start from fs_ck {} only Please advise #!/bin/bash logging {} fs_ck {} bkp {} dply {} ## main function### echo Sstarting script echo '####' logging fs_ck... (3 Replies)
Discussion started by: abhaydas
3 Replies

2. UNIX for Beginners Questions & Answers

How to create a new mount point with 600GB and add 350 GBexisting mount point? IN AIX

How to create a new mount point with 600GB and add 350 GBexisting mount point Best if there step that i can follow or execute before i mount or add diskspace IN AIX Thanks (2 Replies)
Discussion started by: Thilagarajan
2 Replies

3. Red Hat

How to create local mount point at startup?

how to create local mount point at startup Filesystem GB blocks Free %Used Iused %Iused Mounted on xxxxxxxx 370.00 180.08 51% 24500 1% /test (5 Replies)
Discussion started by: karthik9358
5 Replies

4. Shell Programming and Scripting

Fetch the different data by searching with a same variable from a file in AIX server

Hi, I am trying to fetch the different values in an xml file by searching with the same variable in AIX Server. <name>SharedResources/Shared/JNDI/Username</name> <value>admin</value> <name>SharedResources/Shared/JNDI/Username</name> ... (1 Reply)
Discussion started by: tejastrikez
1 Replies

5. Shell Programming and Scripting

Need to create concatenate the shell variable with file content

Hi Guys, I have a file. Each record needs to inserted into a table. The table also have other columns which needs to be inserted with Shell variables. The following is the file. Error code None. Error Code 1 The shell script is having these variables. Name=Magesh Dep=Coding ... (1 Reply)
Discussion started by: mac4rfree
1 Replies

6. Shell Programming and Scripting

Read a file and create egrep variable

I want to create a egrep variable from a file. For example: string=`cat query.txt` cat myfile.txt | egrep "$string" The string variable file has a list of one or multiple lines So the end result of: cat myfile.txt | egrep "$string" would be: cat myfile.txt | egrep... (2 Replies)
Discussion started by: numele
2 Replies

7. UNIX for Dummies Questions & Answers

Searching a text file and assigning it to a variable

Hi Gurus, I am new to unix.I have a requirement as below I have text file like a.txt which contains a.txt hi hello process update status Ok to Proceed no issues good data arrangement My requirement here is i need to read the file and check for the words "OK to Proceed" and if... (2 Replies)
Discussion started by: pssandeep
2 Replies

8. Shell Programming and Scripting

setting a variable by searching within a file

Hi, I am trying to set a variable to be used in later scripting, and am having some difficulty. I want to look in a file called scan.info and find the line that says "variable ok". Then I want to cut the number at the beginning of that line and assign that number as a variable so that later... (4 Replies)
Discussion started by: garth6@hotmail.
4 Replies

9. Linux

How to create file on Linux using environment variable in the dirpath

Hi all, I am running a Java program on a Linux server in which I read in a base directory path from the *.properties file. During processing, I build a unique file name and create a file to save data, concatenating the directory path and the file name. Works fine, except that I now need to... (2 Replies)
Discussion started by: patricia1of5
2 Replies

10. Shell Programming and Scripting

Create new file by searching another file

Hi , I need to write a korn shell to read a file, say Test.txt, and search the file for key words like "email", "name", etc line by line. Whatever is found on a line, send it to an output file. Do this until the end of the file. I have the following code below, that I'm trying to tweak but it... (13 Replies)
Discussion started by: leo
13 Replies
Login or Register to Ask a Question

Featured Tech Videos