I have a file like this
-------------------------------
[2012-11-12 : 11:59
some text
some moe text
ERR-XXXXX
soe more text
]
[2012-11-12 : 12:00 blala blah blah]
[2012-11-12 : 12:01
some text
some moe text
ERR-XXXXX
soe more text
]
[2012-11-12: 12:02 some other text ]
--------------------------------------
I need a way to find the timestamp preceding the ERR-XXXXX
Here XXXX deonoes any any numeric string 00000-99999
that is a output like this
2012-11-12 : 11:59-ERR-XXXXX
2012-11-12 : 12:01-ERR-XXXXX
awk '/\[2012/{a=$0}/^ERR/{print a"-"$0}' input.txt
[2012-11-12 : 11:59-ERR-XXXXX
[2012-11-12 : 12:01-ERR-XXXXX
---------- Post updated at 10:01 AM ---------- Previous update was at 09:59 AM ----------
awk '/\[2012/{sub("\\[","",$0);a=$0}/^ERR/{print a"-"$0}' input.txt
2012-11-12 : 11:59-ERR-XXXXX
2012-11-12 : 12:01-ERR-XXXXX
1 Like
the command is working in the shell.
However when calling this same command from a function
$0 is getting replaced by KSH and the date part is not coming only ERR part is coming
like this
-ERR-XXXXX some more text
-ERR-XXXXX some other text
can you show your function and how you are calling the function?
myFunc(){
echo "In Function ...processing $1"
echo "awk '/\[$1/{sub("\\[","",$0);a=$0}/^ORA/{print a"-"$0}'"
awk '/\[$1/{sub("\\[","",$0);a=$0}/^ERR/{print a"-"$0}' $2.log>>$3
awk '/\[$1/{sub("\\[","",$0);a=$0}/^ERR/{print a"-"$0}' $2_$4>>$3
awk '/\[$1/{sub("\\[",""$0);a=$0}/^ERR/{print a"-"$0}' $2_$5>>$3
}
Calling
myFunc "$currentMonth\/$currentDay\/$currentYearYY" SystemOut $inputFile "$currentYearYY.$currentMonth0.$currentDay0*" $prevDayYr.$prevDayMonth.$prevDayDay