using todays date to create a report using grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using todays date to create a report using grep
# 1  
Old 11-01-2008
using todays date to create a report using grep

What i'm trying to do is to use grep to search through a few files for a selected daemon and only report on today's date.
I think I got it sorted apart from in the txt file the date has 2 gaps between the month and the day, and the way I have the date format only puts in one gap any help to get the 2 gaps would be greatly received or maybe another method to get the report

Code:
td=$(date '+%b  %d')
grep -n $dinput /var/log/message* | grep "$td" >> /home/report.txt

# 2  
Old 11-01-2008
Try this..

I am not having any problem in using this..

I created one txt file with two lines.

$ cat checking.txt
Date operation
Nov 02

Then executed the below commands

$ td=$(date '+%b %d')
$ $ grep "$td" checking.txt
Nov 02

Got the Output with two spaces in between.

So check whether the month are in caps in the files.

you know one thing, the below two commands give different results.

$ td=$(date '+%b %d')
$ echo "$td"
Nov 02

It has two spaces in-between

$ echo $td
Nov 02

It has one space in-between
# 3  
Old 11-01-2008
Quote:
Originally Posted by muruganksk
you know one thing, the below two commands give different results.

As they should.
Quote:
$ td=$(date '+%b %d')
$ echo "$td"
Nov 02

It has two spaces in-between

$ echo $td
Nov 02

It has one space in-between

echo prints its arguments separated by a single space.

If you quote $td, you are giving echo one argument. If you don't quote it, the shell expands the variable and performs word splitting on the result, giving two arguments to echo.
# 4  
Old 11-02-2008
Quote:
Originally Posted by muruganksk
I am not having any problem in using this..

I created one txt file with two lines.

$ cat checking.txt
Date operation
Nov 02

Then executed the below commands

$ td=$(date '+%b %d')
$ $ grep "$td" checking.txt
Nov 02

Got the Output with two spaces in between.

So check whether the month are in caps in the files.

you know one thing, the below two commands give different results.

$ td=$(date '+%b %d')
$ echo "$td"
Nov 02

It has two spaces in-between

$ echo $td
Nov 02

It has one space in-between
I have just realized that the log file I was trying to grep saves any single dates as eg: Nov 2 with 2 spaces not Nov 02 Smilie so when I created the script it was the 1st of Nov so the today variable wouldn't have worked so my prob is to try and get today's date format to output 1 didget with a double space for the single days as i tried to hard code the date as the below code and it worked

Code:
grep -n $dinput /var/log/message* | grep 'Nov  2' >> /home/report.txt


Last edited by MBN; 11-02-2008 at 04:33 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

2. UNIX for Dummies Questions & Answers

Help in script to check file name with todays date

I am trying to include a snippet in my script to check if the file created is having today's date. eg: File name is : ABC.YYYYMMDD-nnn.log The script should check if 'YYYYMMDD' in the above file name matches with today's date. Can you please help me in achieving this. Thanks in advance!! (5 Replies)
Discussion started by: kiran1112
5 Replies

3. UNIX for Dummies Questions & Answers

Make directory with todays date format

Not sure why this is not working. Please advice: #!/bin/sh DIR=`date +"%m-%d-%y"` echo $DIR ] && mkdir $DIR (2 Replies)
Discussion started by: iaav
2 Replies

4. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

5. Shell Programming and Scripting

Find files having todays date and hostname in its name.

Hello, I am quite new to unix/shell and want to write a script using bash which will process the files. Basically i want to search files having name as "date+hostname+somestring.out" i am using below variables and then will use them in find command :- TODAY_DATE=$('date +%d')... (5 Replies)
Discussion started by: apm
5 Replies

6. Shell Programming and Scripting

Perl Script to execute todays date.

Hi Folks, I have created a script last month to retrive files thru FTP and cronjob was running fine till yesterday. But the naming convention of the daily file is Filename_<date>.xml where date is YYYYMMDD. But today i have received file name as Filename_20110232.xml :( Part of my Perl... (4 Replies)
Discussion started by: Sendhil.Kumaran
4 Replies

7. Shell Programming and Scripting

Bash: create a report with grep output?

Greetings. I need to generate a simple report via Bash (Korn?) with this raw data Test_Version=V2.5.2 Test_Version=V2.6.3 Test_Version=V2.4.7 Test_Version=V2.5.2 Test_Version=V2.5.2 Test_Version=V2.5.1 Test_Version=V2.5.0 Test_Version=V2.3.9 ... (3 Replies)
Discussion started by: alan
3 Replies

8. Shell Programming and Scripting

How to grep a string in todays file

Hello guys - I am new to Unix. I am trying to understand how to grep a perticular string in todays file? I am trying this syntax but not getting what I am looking for: % grep `date '+%d/%b/%Y'` For instance there are 2 files generated today with same data. I am trying to find them and... (21 Replies)
Discussion started by: DallasT
21 Replies

9. Linux

Comparing the file drop date with todays date

Daily one file will dropped into this directory. Directory: /opt/app/jt/drop File name: XXXX_<timestamp>.dat.gz I need to write a script which checks whether the file is dropped daily or not. Any idea in the script how can we compare timestamp of the file to today's date?? (3 Replies)
Discussion started by: Rajneel
3 Replies

10. UNIX for Dummies Questions & Answers

Get yesterdays date given todays date

Hi Guys. I am very new to UNIX. I need to get yesterdays and tommorows date given todays date. Which command and syntax do i use in basic UNIX shell. Thanks. (2 Replies)
Discussion started by: magikminox
2 Replies
Login or Register to Ask a Question