Shell Variable in Curly Brackets Returns Empty Value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Variable in Curly Brackets Returns Empty Value
# 1  
Old 05-02-2012
Shell Variable in Curly Brackets Returns Empty Value

Hello Team,

I have a script which will grep for a time from a file. I have following code to grep for a time in a file.

Code:
node=`hostname`

current_date=`date`

file11=weblogic.log

next_date=`date '+%b %e, %Y'`

next_date_time11=`grep -i "${#next_date}" ${file11}| tail -1 | awk '{print $4}'`

When I do echo to variable next_date_time11 it returns null value.

I am trying to get time from the below file. I am unable to do that.

Kindly help

Below is the file content :-

Code:
<May 2, 2012 1:14:50 PM MEST> <Error> <HTTP> <BEA-101214> <Included resource or file "/eMatrix/jsp/mars/report/optionFragments/baseline_options.jsp" not foun
d from requested resource "/eMatrix/jsp/mars/report/report.jsp".>
submitMode=viewreport
<May 2, 2012 1:17:53 PM MEST> <Error> <HTTP> <BEA-101214> <Included resource or file "/eMatrix/jsp/mars/report/optionFragments/baseline_options.jsp" not foun
d from requested resource "/eMatrix/jsp/mars/report/report.jsp".>
submitMode=viewreport


Last edited by Scrutinizer; 05-02-2012 at 08:21 AM.. Reason: code tags instead of quote tags
# 2  
Old 05-02-2012
Hi: ${#next_date} means length of string $next_date. Does your input file contains newlines like that?
# 3  
Old 05-02-2012
Hello ,

Thanks for the response.

My file contains following line in it.

Code:
<May 2, 2012 1:14:50 PM MEST> <Error> <HTTP> <BEA-101214> <Included resource or file "/eMatrix/jsp/mars/report/optionFragments/baseline_options.jsp" not foun
d from requested resource "/eMatrix/jsp/mars/report/report.jsp".>
submitMode=viewreport
<May 2, 2012 1:17:53 PM MEST> <Error> <HTTP> <BEA-101214> <Included resource or file "/eMatrix/jsp/mars/report/optionFragments/baseline_options.jsp" not foun
d from requested resource "/eMatrix/jsp/mars/report/report.jsp".>
submitMode=viewreport

I would like to get the time stamp "1:14:50" from the file.

Kindly help
Moderator's Comments:
Mod Comment Please use [code][/code] tags instead of [quote][/quote] tags for code and samples
# 4  
Old 05-02-2012
In the log file there is only one space between May and 2. You can try: date '+%b%e, %Y' but I don't know if that would work for double digit days of the month..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove the text between all curly brackets from text file?

Hello experts, I have a text file with lot of curly brackets (both opening { & closing } ). I need to delete them alongwith the text between opening & closing brackets' pair. For ex: Input:- 59. Rh1 Qe4 {(Qf5-e4 Qd8-g8+ Kg6-f5 Qg8-h7+ Kf5-e5 Qh7-e7+ Ke5-f5 Qe7-d7+ Qe4-e6 Qd7-h7+ Qe6-g6... (6 Replies)
Discussion started by: prvnrk
6 Replies

2. Shell Programming and Scripting

Curly brackets converted to unicode in script

Is this a bash or wget issue? GNU bash, version 4.4.0(1)-release (x86_64-slackware-linux-gnu) GNU Wget 1.18 built on linux-gnu. If I run wget -O file localhost/{2..4} from the command line, it will download pages 2 to 4 and concatenate them to file - which is what I want. If I put this in a... (4 Replies)
Discussion started by: Ray-V
4 Replies

3. Shell Programming and Scripting

Grepping for variable in brackets

I have a script which reads a number out of a log file. The pertinent line is this: cat /tmp/listofnumbers When I run cat /tmp/listofnumbers what I am seeing is on each line. I am trying to make the script read from that file and grep for a variable like the following line should do: ... (4 Replies)
Discussion started by: newbie2010
4 Replies

4. Shell Programming and Scripting

Function returns a value but cannot be stored in other variable

I need help to store the value returned from the function to one variable and then use that variable. PREVIOUS_DATE_FUNCTION() { date '+%m %d %Y' | { read MONTH DAY YEAR DAY=`expr "$DAY" - 1` case "$DAY" in 0) MONTH=`expr "$MONTH" - 1` case... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

5. Shell Programming and Scripting

set variable with square brackets in c shell!

Hi Guys, I want to set a variable which happend to have square brackets in them. I tried multiple ways that is by escaping it with quotes (both single and double ) but it didn't help. All I want is: set x = slicearray.slice\.post My failed attempts were: set x = "slicearray.slice\.post"... (3 Replies)
Discussion started by: dixits
3 Replies

6. Shell Programming and Scripting

Python call to bash script returns empty string

Hi all, I need help figuring out why my script won't work when envoked from web interface. First off, I'm fairly new to Linux and Shell scripting so, my apologies for being ignorant! So I have a python script that I envoke through a web interface. This script envokes my shell script and... (8 Replies)
Discussion started by: arod291
8 Replies

7. Shell Programming and Scripting

sqlplus returns leading carriage return into a variable

I am trying to generate some scripts to help manage an Oracle database. When I check the value returned from Oracle it has a leading carriage return in the variable. Is there a way to prevent this? Is there a way to easily strip out the carriage return. See code and output below. ... (7 Replies)
Discussion started by: Panzer993
7 Replies

8. UNIX for Dummies Questions & Answers

grep returns many values into a variable error

I get an error when I grep my results into a variable when the grep finds more than one file. FND="$(find ediout* -mmin -60)" if ; then STR="$(find ediout* -mmin -60 -exec grep -l "ERRORS Encountered" {} +)" fi When there is only one ediout file it works fine. How do I... (11 Replies)
Discussion started by: aispg8
11 Replies

9. Shell Programming and Scripting

awk print last line returns empty string

hello I have a file with lines of info separated with "|" I want to amend the second field of the last line, using AWK my problem is with geting awk to return the last line this is what I am using awk 'END{ print $0 }' myFile but I get an empty result I tried the... (13 Replies)
Discussion started by: TasosARISFC
13 Replies

10. UNIX for Dummies Questions & Answers

Brackets, parentheses in Shell Scripting

Hello, I have done a great deal of research on this and still cannot come to an understanding of the following: In if-else statements in shell scripting I have seen examples of single brackets, double brackets, single parantheses, and double paratheses. When should each one be used? And... (2 Replies)
Discussion started by: mojoman
2 Replies
Login or Register to Ask a Question