Find the answer to your Linux question:
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 ...
  1. #1
    Just 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

  2. #2
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Please post sample input and an example of the desired output.

  3. #3
    Just 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

  4. #4
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Yes,
    as I said, post sample from the input and example (not description) of the desired output.

  5. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Seems a pretty clear statement of the requirement to me.
    Code:
    awk '
    /_sel$/  {print $0 "_aa01"; next}
    /_del$/  {print $0 "_bb01"; next}
                 {print $0 "_'$(date +%Y%m%d)'"}' inputfile
    Adjust the date command to give the format you require (but avoid including slash characters (/)!).

  6. #6
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    This should be sufficient:

    Code:
    awk '
    $0=$0"_"(/[sd]el$/?(/_sel$/?"aa":"bb")"01":d)
    ' d="$(date +%F)" file
    Avoid calling the external date command for every matching record ...

    I prefer to have an example in/output though ...

Posting Permissions

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