How to test each line in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to test each line in a file
# 15  
Old 12-16-2011
Hi CarloM/Guys,

Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this:
Code:
Command was launched from partition 0.


------------------------------------------------
Executing command in server server6
Fri Dec 16 13:56:44 EET 2011


------------------------------------------------
Executing command in server server3
Fri Dec 16 13:56:44 EET 2011


------------------------------------------------
Executing command in server backup-server
Fri Dec 16 13:56:44 EET 2011


------------------------------------------------
Executing command in server server1
Fri Dec 16 13:56:45 EET 2011

What I want to do is to check even just the DAY DATE HH:MM of the results versus the current system date/time.

Please advice,
rymnd_12345
# 16  
Old 12-19-2011
Code:
[user@host2: /tmp] checkdate=$(date "+%a %b %d")
[user@host2: /tmp] echo $checkdate
Mon Dec 19
[user@host2: /tmp] grep "$checkdate" 1.txt
Mon Dec 19 13:56:44 EET 2011
Mon Dec 19 13:56:44 EET 2011
Mon Dec 19 13:56:44 EET 2011
Mon Dec 19 13:56:45 EET 2011
[user@host2: /tmp] awk -vchkdate="$checkdate" '$0 ~ chkdate' 1.txt
Mon Dec 19 13:56:44 EET 2011
Mon Dec 19 13:56:44 EET 2011
Mon Dec 19 13:56:44 EET 2011
Mon Dec 19 13:56:45 EET 2011

The exact options for date may depend on your OS - check the man page.
# 17  
Old 12-19-2011
Hi CarloM,

Thanks again for your help! I wish you've read my new post, if so I appreciate any input from you. BTW this is the post... I have a file that conatins output upon executing/var/log/messages, then what I want is to get the logs that has been generated only starting from 24-hours earlier at the time of actual execution of the script. Is this possible? Let's say for example:
Code:
$cat /var/log/messages > output-file
$cat output-file
-----> outputs multiple files regardless of its date

I want that when I run the parser it will just give me the output 24-hrs earlier from the time of execution.


Br,
rymnd_12345
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find Data in test file and write each out to a line

I have a .csv file that has been create from a google form and I need to extract the data from it that has been entered by users. The CSV will have anywhere between 100 and 1000 lines which comprise entr data for a sports carnival A few typical line is shown here to show the problem I have ... (19 Replies)
Discussion started by: kcpoole
19 Replies

2. Shell Programming and Scripting

How do I test the first char of each line in an array

Hi folks, I am self-learning as I can I have a script that has read a file into an array. I can read out each line in the array with the code: for INDEX in {0..$LENGTH} ## $LENGTH was determined at the read in do echo "${data}" done What I need to do is test the first char... (2 Replies)
Discussion started by: Marc G
2 Replies

3. Shell Programming and Scripting

Get last lines of file after last line with word TEST

i need to get least lines of file after last word TEST in file, and send that lines to mail example of file structure: TEST 10.10.2010 jdfjdnjfndjfndnfkdk djfjdnfjkdjkfnjkdfk jdfjdjfnjdjnfjkdnfjk TEST 11.10.2010 jdjfnjdnfdkdfjdfjdnk jdnfjdnjkfndnfjdnfjk fjdnfjkndnfdfnjdnfjk TEST... (6 Replies)
Discussion started by: waso
6 Replies

4. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

5. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

6. UNIX for Dummies Questions & Answers

What's wrong with this line: if ${TEST:?} ; then echo empty; fi

I want to print "empty" if $TEST is empty. TEST= if ${TEST:?} ; then echo empty; fi But it doesn't work. What's wrong? (2 Replies)
Discussion started by: meili100
2 Replies
Login or Register to Ask a Question