Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all i want to create a script in which it will read a file and if in that file there would be any word DEV at he end of ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    20

    search from a file

    Hi all

    i want to create a script in which it will read a file and if in that file there would be any word DEV at he end of the line it will appand iii01at the end otherwise it will append aa01 at the end of the file.

    cat dd.txt
    jhdhjdfh5453_DEV
    apple_DEV
    linewithout123456
    hello
    hello_DEV

    Please help.
    Thanks,
    Inder

  2. #2
    Just Joined!
    Join Date
    Apr 2008
    Posts
    35
    Hey There,

    You can probably do it taking up even less space than this, but this should do the trick for you

    Code:
    awk '{ if ( $NF ~ /DEV/ ) print $0 "iii01";else print $0 "aa01" }' dd.txt
    Hope that helps

    , Mike

  3. #3
    Just Joined!
    Join Date
    Jan 2008
    Posts
    20
    Thanks Mike, it works for me..
    Thanks you very much ..

  4. #4
    Just Joined!
    Join Date
    Apr 2008
    Posts
    35
    Your very welcome. Glad to help

    , Mike

  5. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Another variant:
    Code:
    awk '/DEV$/ {print $0 "iii01"; next}
    {print $0 "aa01"}' dd.txt

Posting Permissions

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