Remove String from file - VMS

This is a discussion on Remove String from file - VMS ; Hi, I was after a way in which I could remove some specific text from a file without using an editor i.e via a lexical or dcl script. For example if I have a file with the contents below : ...

+ Reply to Thread
Results 1 to 10 of 10

Thread: Remove String from file

  1. Remove String from file

    Hi,

    I was after a way in which I could remove some specific text from a
    file without using an editor i.e via a lexical or dcl script. For
    example if I have a file with the contents below :

    hello
    this
    is
    my file
    is
    hello

    I would like to remove every instance of the string "is" and also the
    whole line from the file so that the file looks like

    hello
    this
    my file
    hello

    If anyone has any thoughts on how to achieve it would be greatly
    appreciated.

    thanks

  2. Re: Remove String from file

    In article , Ruger writes:

    > I would like to remove every instance of the string "is" and also the
    > whole line from the file so that the file looks like


    Assuming you mean remove records that exactly match the string "is",
    which your example implies, then on VMS 8.2 and higher:

    $ search a.a is/wild=strict/match=nor/out=b.b


  3. Re: Remove String from file

    In article <6exU6mc5VU$3@eisner.encompasserve.org>, burley+news@encompasserve.org (Graham Burley) writes:

    > Assuming you mean remove records that exactly match the string "is",
    > which your example implies, then on VMS 8.2 and higher:
    >
    > $ search a.a is/wild=strict/match=nor/out=b.b
    >


    Er, and if exact means exact, then case might be important ...

    $ search a.a "is"/wild=strict/match=nor/exact


  4. Re: Remove String from file

    Thanks Graham,

    I'm running 7.1-2 but it works okay on what I need to do


  5. Re: Remove String from file

    Graham Burley wrote:
    > In article , Ruger writes:
    >
    >> I would like to remove every instance of the string "is" and also the
    >> whole line from the file so that the file looks like

    >
    > Assuming you mean remove records that exactly match the string "is",
    > which your example implies, then on VMS 8.2 and higher:
    >
    > $ search a.a is/wild=strict/match=nor/out=b.b
    >


    That will remove the line with "this" also, if I'm not wrong...

    Jan-Erik.

  6. Re: Remove String from file

    On Feb 5, 7:39*pm, burley+n...@encompasserve.org (Graham Burley)
    wrote:
    > In article <6exU6mc5V...@eisner.encompasserve.org>, burley+n...@encompasserve.org (Graham Burley) writes:
    >
    > > Assuming you mean remove records that exactly match the string "is",
    > > which your example implies, then on VMS 8.2 and higher:

    >
    > > $ search a.a is/wild=strict/match=nor/out=b.b

    >
    > Er, and if exact means exact, then case might be important ...
    >
    > $ search a.a "is"/wild=strict/match=nor/exact


    interestingly, the 'almost' match in 'this' will be highlighted for
    terminal output!

    fwiw... a basic DCL loop solution:

    $IF p3.EQS."" THEN EXIT 16
    $OPEN/READ inp 'p1
    $OPEN/WRIT out 'p2
    $loop:
    $READ/END=done inp record
    $IF record.NES.p3 THEN WRITE out record
    $GOTO loop
    $done:
    $CLOSE inp
    $CLOSE out

    AWK:

    $ gawk /command="!/^is$/" old

    And in PERL:

    $perl -ne "print unless /^is$/" old > new

    or the much more obsure

    $ perl -pe "m m ^is$ mx and $ _= $ m" old > new

    Hein.





  7. Re: Remove String from file

    In article , =?ISO-8859-1?Q?Jan-Erik_S=F6derholm?= writes:

    >> $ search a.a is/wild=strict/match=nor/out=b.b
    >>

    >
    > That will remove the line with "this" also, if I'm not wrong...
    >


    Using /WILD=STRICT means it'll only match whole records.

    $ HELP SEARCH/WILDCARD_MATCHING


  8. Re: Remove String from file

    Graham Burley wrote:

    > In article , =?ISO-8859-1?Q?Jan-Erik_S=F6derholm?= writes:
    >
    >>>$ search a.a is/wild=strict/match=nor/out=b.b
    >>>

    >>
    >>That will remove the line with "this" also, if I'm not wrong...

    >
    > Using /WILD=STRICT means it'll only match whole records.
    >
    > $ HELP SEARCH/WILDCARD_MATCHING


    Note that the "=STRICT" and "=RELAXED" extras were added in VMS 8.3;
    they did not exist previous to that.

  9. Re: Remove String from file

    In article , Ruger writes:
    > Hi,
    >
    > I was after a way in which I could remove some specific text from a
    > file without using an editor i.e via a lexical or dcl script. For
    > example if I have a file with the contents below :


    Basic DCL programming. You can find it in lots of places on the
    'net.

  10. Re: Remove String from file

    R.A.Omond wrote:
    > Graham Burley wrote:
    >
    >> In article ,
    >> =?ISO-8859-1?Q?Jan-Erik_S=F6derholm?= writes:
    >>
    >>>> $ search a.a is/wild=strict/match=nor/out=b.b
    >>>>
    >>>
    >>> That will remove the line with "this" also, if I'm not wrong...

    >>
    >> Using /WILD=STRICT means it'll only match whole records.
    >>
    >> $ HELP SEARCH/WILDCARD_MATCHING

    >
    > Note that the "=STRICT" and "=RELAXED" extras were added in VMS 8.3;
    > they did not exist previous to that.


    Well, another reason to upgrade... :-)

+ Reply to Thread