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.
- 02-24-2013 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 30
Passing parameters to awk?
Hii,
Contents of the log
I need to write a script such that,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
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:
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:awk '/2013-02-23 11/,/2013-02-23 12/' test
It generates the entire file as output and not filtered.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
I also tried to export the etime and stime variables but can;t get the desired output. Please help...
Regards,
Zoheb
- 02-24-2013 #2Linux Newbie
- Join Date
- Nov 2012
- Posts
- 136
hi,
in shell, variables are not expanded between single quotes.
- 02-24-2013 #3Just Joined!
- Join Date
- Mar 2011
- Posts
- 30
What if I try something like below? Should it work?
coz this ain't working for me.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
Though I verify the substitution by
It displays the expected output in stime and etime vars. But still not getting the filtered result.Code:echo "awk '/$stime/,/$etime/' test "
Do I need to convert date? (which is currently as a string)
- 02-24-2013 #4Linux Newbie
- Join Date
- Nov 2012
- Posts
- 136
in shell, variables are not expanded between single quotes.Code:$ var="a b c" $ echo "$var" a b c $ echo "$var" a b c $ echo "'$var'" 'a b c' $ echo '$var' $var
- 02-24-2013 #5Just Joined!
- Join Date
- Mar 2011
- Posts
- 30
so what would be your approach to get this done?
- 02-24-2013 #6Linux Newbie
- Join Date
- Nov 2012
- Posts
- 136
Code:awk -v s="$stime" -v e="$etime" '$0~s,$0~e' test >loginattempts


Reply With Quote
