Grep with loop till search is done


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep with loop till search is done
# 1  
Old 06-21-2013
Grep with loop till search is done

I need help to put a script where it runs the svn command grep'ing for the ticket# in the comments to see if the ticket was used in the latest commit.

so on command line:
./test.sh ticket-1 ticket-2 ticket-3

It should be able to check if ticket-1 is used first and if not then check if ticket-2 is used and so on ...

Code:
svn log -v //test.svn.com/svn/demoproject/helloworld --limit 1| grep ticket-1

I have this so far:
my testfile has all the java filenames and i'm passing the ticket numbers as args But i need help to run the grep part in loop to check the tickets one after the other

Code:
#!/usr/bin/bash

src_url="$1" ; shift

while read line

do

    check=($(IFS=$'\n'; svn log $src_url/$line --limit 1 | grep "$ticket")) ---- "help here to have a loop to check the tickets one after the other"

    if [[ "${#check[@]}" -eq 0 ]]; then

    echo "None of the tickets mentioned were used.."

    fi

done < "testfile"


Last edited by iaav; 06-21-2013 at 07:20 PM..
# 2  
Old 06-21-2013
Quote:
Originally Posted by iaav
so on command line:
./test.sh ticket-1 ticket-2 ticket-3
.
.
Code:
#!/usr/bin/bash
src_url="$1" ; shift

When you do the above, src_url would be "ticket-1". After shift, $1 would refer to ticket-2. Not sure if this is what you want. Please re-check.

Here's an untested script:

Code:
#! /usr/bin/bash

src_url='//test.svn.com/svn/demoproject/helloworld'

while read line
do
    flag=0
    for ticket in $@
    do
        svn log $src_url/$line --limit 1 | grep -q "$ticket"
        if [ $? -eq 0 ]
        then
            flag=1
        fi
    done
    
    if [ $flag -eq 0 ]
    then
        echo "In $line, none of the tickets were found"
    fi
done < "testfile"

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 06-24-2013
Thanks this worked.

Also the shift part of the script works okay. takes only the args after URL as tickets
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. Shell Programming and Scripting

Number of words in line, while loop, search and grep

Hello, What I wish to attain is: - to read fileA line by line - search entire line as string in fileB - when found, grep the next line in fileB - then merge "searched line" and "found line" in a new file, fileC Here is my fileA: T S Eliot J L Borges L Aragon L L Aragon T S Eliot 4 0... (17 Replies)
Discussion started by: baris35
17 Replies

3. Shell Programming and Scripting

Sleep till grep find the string

Hello! I have a sample code in which a grep is being performed from multiple files with a date format in their naming convention. Here the script: #! /usr/bin/bash cd /IN/service_packages/SMS/cdr/received MYDATE=`date +"%Y%m%d%H%M"` #get the value then divide by 60 #DAPS_SLC01... (3 Replies)
Discussion started by: nms
3 Replies

4. Shell Programming and Scripting

While loop till length of line is great enough

I have the following code: # Get the line of stations_info.txt starting with "${xstation1} " and copy it to file temp.txt grep "^${xstation1} " stations_info.txt > temp.txt # Get lat and long of station nl=0 ... (2 Replies)
Discussion started by: claire.a
2 Replies

5. Shell Programming and Scripting

For loop till the files downloaded

Need assistance in writing a for loop script or any looping method. Below is the code where i can get all the files from the URL . There are about 80 files in the URL .Every day the files get updated . Script that i wanted is the loop must keep on running till it gets 80 files. It matches the count... (5 Replies)
Discussion started by: ajayram_arya
5 Replies

6. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

7. Shell Programming and Scripting

How to grep after the first comma till the next comma in a line

Hi Can any one pls tell me how to grep this line POPULATION,69691,20120509 I want the number 69691 from the above line. How to grep from the first comma till the next comma. Thank You.:confused: (8 Replies)
Discussion started by: rxg
8 Replies

8. Shell Programming and Scripting

Grep from a starting line till the end of the file

Hi Folks, I got to know from this forums on how to grep from a particular line say line 6 awk 'NR==6 {print;exit}' But how do i grep from line 6 till the end of the file or command output. Thanks, (3 Replies)
Discussion started by: Mr. Zer0
3 Replies

9. Shell Programming and Scripting

How to print lines till till a pattern is matched in loop

Dear All I have a file like this 112534554 446538656 444695656 225696966 226569744 228787874 113536566 443533535 222564552 115464656 225445345 225533234 I want to cut the file into different parts where the first two columns are '11' . The first two columns will be either... (3 Replies)
Discussion started by: anoopvraj
3 Replies

10. UNIX for Dummies Questions & Answers

Loop till you find a string in a fine <-- Need Help New to Unix Scripting

Guys - I am new to Unix scripting and am in need for a script that does the following. I have bits and pieces created and tested but i am just having a little difficult time getting it all together. - Loop through till it finds a string in a specific file. Any help is greatly appreciated. ... (1 Reply)
Discussion started by: mrehman
1 Replies
Login or Register to Ask a Question