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 ...
- 06-05-2008 #1Just 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
- 06-05-2008 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
Instead of '/DEV/$' use '/(DEV|dev)$/'
- 06-05-2008 #3Just 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.
- 06-05-2008 #4Linux User
- Join Date
- Jun 2007
- Posts
- 318
Replace the '!/DEV$' with '!/dev$/&&!/DEV$/'
- 06-05-2008 #5
With GNU Awk:
Otherwise:Code:awk '$0=$0(/dev$/?"_BLD01":"_RC01")' IGNORECASE=1 input
Code:awk '$0=$0(/[dD][eE][vV]$/?"_BLD01":"_RC01")' input
- 06-05-2008 #6Just 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.
- 06-05-2008 #7Just Joined!
- Join Date
- Jan 2008
- Posts
- 20
Thanks Vsemaska,
It is working fine, issue was at my end.
Thanks a lot.


Reply With Quote