Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    37

    Unanswered: Shell script to SEARCH multiple string occurances

    I need search the strings in the text file that has the following information:


    INSERT INTO TEST123
    values (1,2,3);

    INSERT INTO ABCD
    values (1,2,3);

    UPDATE TEST123
    SET
    ABC='123'
    WHERE ABC='124';

    UPDATE ABCD
    SET
    ABC='123'
    WHERE ABC='124';

    DELETE FROM TEST123
    WHERE ABC = '111'
    AND DEF= '222'
    AND GHI='333';


    DELETE FROM ABCD
    WHERE ABC = '111'
    AND DEF= '222'
    AND GHI='333';

    How could I Search for the string "TEST123" and then search for the following character ";".

    Once these two strings are found, I want to Copy the data from line1(FIRST STRING FOUND) and lineN(SECOND STRING FOUND) to another file..


    NEW FILE OUTPUT:


    INSERT INTO TEST123
    values (1,2,3);

    UPDATE TEST123
    SET
    ABC='123'
    WHERE ABC='124';

    DELETE FROM TEST123
    WHERE ABC = '111'
    AND DEF= '222'
    AND GHI='333';


    Any help is appreciated

  2. #2
    Join Date
    Aug 2004
    Location
    Rome, Italy
    Posts
    81
    Hi Gomes,
    use this:

    awk '{printf $0}' old.file.name|awk 'BEGIN{RS=";"}{print $0 ";"}'|grep -i "test123" > new.file.name

    bye,
    ducasio

  3. #3
    Join Date
    Feb 2004
    Posts
    37
    Thank you!!!

    It works like a charm!!!

  4. #4
    Join Date
    Sep 2006
    Location
    Mumbai,India
    Posts
    2

    Use egrep command

    i think egrep command will help you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •