Results 1 to 6 of 6
Hi All,
I want to create a script in which i want to fulfill three conditions with awk command.
I want to search from a sentence if there is sel ...
- 06-17-2008 #1Just Joined!
- Join Date
- Jan 2008
- Posts
- 20
AWK Help
Hi All,
I want to create a script in which i want to fulfill three conditions with awk command.
I want to search from a sentence if there is sel at the end of string, then it append "_aa01", if it has del at end it will append "_bb01", if nothing between both conditions it will append "$DATE"
if i can satisfy these all three conditions without awk, please let me know with examples.
Please help.
Thanks,
Inder Punj
- 06-18-2008 #2
Please post sample input and an example of the desired output.
- 06-18-2008 #3Just Joined!
- Join Date
- Jan 2008
- Posts
- 20
The 3 comdition should be as follows :-
1. Let i have inder_eatapple_sel then it will append _aa01 at the end, LIKE - inder_eatapple_sel_aa01
2. If i have inder_eatapple_del then it will append _bb01 at the end LIKE - inder_eatapple_del_bb01
3. if it has not sel nor del at the end, then it append current date.
Please suggest, if want more clearification , please let me know.
Thanks,
Inder
- 06-18-2008 #4
Yes,
as I said, post sample from the input and example (not description) of the desired output.
- 06-22-2008 #5Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Seems a pretty clear statement of the requirement to me.
Adjust the date command to give the format you require (but avoid including slash characters (/)!).Code:awk ' /_sel$/ {print $0 "_aa01"; next} /_del$/ {print $0 "_bb01"; next} {print $0 "_'$(date +%Y%m%d)'"}' inputfile
- 06-22-2008 #6
This should be sufficient:
Avoid calling the external date command for every matching record ...Code:awk ' $0=$0"_"(/[sd]el$/?(/_sel$/?"aa":"bb")"01":d) ' d="$(date +%F)" file
I prefer to have an example in/output though ...


Reply With Quote