Find the answer to your Linux question:
Results 1 to 7 of 7
Hi All, I am creating a bash script in which i am trying to fulfill the following condition:- a=$(awk '/DEV$/{ print $0 "_BLD01"}!/DEV$/{print $0 "_RC01"}' Inder Here the issue is ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    20

    AWK Help

    Hi All,

    I am creating a bash script in which i am trying to fulfill the following condition:-

    a=$(awk '/DEV$/{ print $0 "_BLD01"}!/DEV$/{print $0 "_RC01"}' Inder

    Here the issue is that it is finding only the word DEV at the end of the line, but i want to seach for "dev" and "DEV" Both at the end of the line.

    If it find DEV or dev it will append BLD01 else RC01

    Kindly Help

    Thanks,
    Inder

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Instead of '/DEV/$' use '/(DEV|dev)$/'

  3. #3
    Just Joined!
    Join Date
    Jan 2008
    Posts
    20
    Thanks, Vsemaska

    $(awk '/(DEV|dev)$/{ print $0 "_BLD01"} !/DEV$/{print $0 "_RC01"}

    It is working but if it opt for dev it will append RC01 and BLD01 both at the end.
    but i want if not dev either DEV , it should also apppend R01.

  4. #4
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Replace the '!/DEV$' with '!/dev$/&&!/DEV$/'

  5. #5
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    With GNU Awk:

    Code:
    awk '$0=$0(/dev$/?"_BLD01":"_RC01")' IGNORECASE=1 input
    Otherwise:

    Code:
    awk '$0=$0(/[dD][eE][vV]$/?"_BLD01":"_RC01")' input

  6. #6
    Just Joined!
    Join Date
    Jan 2008
    Posts
    20
    Hi Vsemaska

    I am trying with :-

    (awk '/(DEV|dev)$/{ print $0 "_BLD01")!/dev$/&&!/DEV$/{print $0 "_RC01"}'
    And

    (awk '/(DEV|dev)$/{ print $0 "_BLD01")(!/dev$/&&!/DEV)$/{print $0 "_RC01"}'

    But i am unable to find desire answer.

  7. #7
    Just Joined!
    Join Date
    Jan 2008
    Posts
    20
    Thanks Vsemaska,

    It is working fine, issue was at my end.
    Thanks a lot.

Posting Permissions

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