Find the answer to your Linux question:
Results 1 to 6 of 6
Hii, Contents of the log Code: 2013-02-23 20:43:03 : 4. Login into Portal for Userwrledger : Session ID:v2n7afvs95tt0222rdklrcdf8s4v5bt9 2013-02-23 20:45:45 : 0. Begin Script : Session ID:3nbb3is5cu5cvt07j2dqo5ppakh7j4dj 2013-02-23 20:45:45 : ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2011
    Posts
    34

    Passing parameters to awk?


    Hii,

    Contents of the log
    Code:
    2013-02-23 20:43:03 : 4. Login into Portal for Userwrledger : Session ID:v2n7afvs95tt0222rdklrcdf8s4v5bt9
    2013-02-23 20:45:45 : 0. Begin Script : Session ID:3nbb3is5cu5cvt07j2dqo5ppakh7j4dj
    2013-02-23 20:45:45 : 1. Check User Login Invoked for username: Spouffbip : Session ID:3nbb3is5cu5cvt07j2dqo5ppakh7j4dj
    2013-02-23 20:45:46 : 2. Check User Login gave Response Code: 10010 for username: Spouffbip : Session ID:3nbb3is5cu5cvt07j2dqo5ppakh7j4dj
    2013-02-23 20:45:46 : 5. Check User Login failed and will give error for username:Spouffbip : Session ID:3nbb3is5cu5cvt07j2dqo5ppakh7j4dj
    2013-02-23 20:45:59 : 0. Begin Script : Session ID:5j8s0pv7r4aba2h6rb1us0nbbih8q8hv
    2013-02-23 20:45:59 : 1. Check User Login Invoked for username: JFessenden : Session ID:5j8s0pv7r4aba2h6rb1us0nbbih8q8hv
    2013-02-23 20:46:03 : 2. Check User Login gave Response Code: 10000 for username: JFessenden : Session ID:5j8s0pv7r4aba2h6rb1us0nbbih8q8hv
    2013-02-23 20:46:03 : 3. Portal Login Invoked for username: JFessenden : Session ID:5j8s0pv7r4aba2h6rb1us0nbbih8q8hv
    I need to write a script such that,

    It takes 2 dates as input (Format: 2013-02-22 Start_hr/ End_hr) .
    List all the contents of the file between Start_hr and End_hr

    The following command does this work:

    Code:
    awk '/2013-02-23 11/,/2013-02-23 12/' test
    But I need to make it dynamic in a way that I will just enter the date and the script will store the o/p to another file.

    Code:
    #!/bin/bash
    
    echo "Enter Start time (2013-02-22 ST):"
    read stime
    
    
    echo "Enter End time (2013-02-22 ET):"
    read etime
    
    command="/$stime/,/$etime/"
    
    awk '$command' test >> loginatmpts
    It generates the entire file as output and not filtered.

    I also tried to export the etime and stime variables but can;t get the desired output. Please help...

    Regards,
    Zoheb

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    hi,

    in shell, variables are not expanded between single quotes.

  3. #3
    Just Joined!
    Join Date
    Mar 2011
    Posts
    34
    What if I try something like below? Should it work?

    Code:
    #!/bin/bash
    
    export stime
    export etime
    
    echo "Enter Start time (2013-02-22 ST):"
    read stime
    
    
    echo "Enter End time (2013-02-22 ET):"
    read etime
    
    command=""
    
    awk '/$stime/,/$etime/' test >> loginatmpts
    coz this ain't working for me.

    Though I verify the substitution by

    Code:
    echo "awk '/$stime/,/$etime/' test "
    It displays the expected output in stime and etime vars. But still not getting the filtered result.

    Do I need to convert date? (which is currently as a string)

  4. #4
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    Code:
    $ var="a b c"
    $ echo "$var"
    a b c
    $ echo "$var"
    a b c
    $ echo "'$var'"
    'a b c'
    $ echo '$var'
    $var
    in shell, variables are not expanded between single quotes.

  5. #5
    Just Joined!
    Join Date
    Mar 2011
    Posts
    34
    so what would be your approach to get this done?

  6. #6
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    Code:
    awk -v s="$stime" -v e="$etime" '$0~s,$0~e' test >loginattempts

Posting Permissions

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