Need to check a file from a certain position and date onwards


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to check a file from a certain position and date onwards
# 1  
Old 04-13-2012
Need to check a file from a certain position and date onwards

Hi Guys,
I need some advice please.

My script is not grabbing information from a text file from a certain date correctly. It seems to be grabbing everying in the file, i know it is something simple but i have looked to hard and to long, to know what the issue is.


Script
Code:
 awk ' BEGIN {ok=0}
        substr($(NF),1,2) >= 11 {ok=1}
        ok==0 {next}
        {print} ' DATE_1=`date +%m/%d/%y` /tmp/test   | grep "Set owner " >> $TMP2/OWNERSHIP_ASSIGNED_INJECTED_$DATE.txt


Script Ouptut
Code:
+ awk  BEGIN {ok=0}
        substr($(NF),1,2) >= 11 {ok=1}
        ok==0 {next}
        {print}  DATE_1=04/13/12 /tmp/test


File Output - OWNERSHIP_ASSIGNED_INJECTED_130412.txt
Code:
Set owner nbkpmstr to CBLJMM   -  Should not be shown, yesterday file input!!
Set owner nbkpmstr to CBL288
Set owner nbkpmstr to CBL011
Set owner nbkpmstr to CBL225
Set owner nbkpmstr to CBL132


File Read - /tmp/test
Code:
$ cat /tmp/test
04/12/12 15:10:25
volume: CBLJMM
Remove prior owner SYSTEM from CBLJMM
Set owner nbkpmstr to CBLJMM

04/13/12 15:10:14
volume: CBL288
Remove prior owner SYSTEM from CBL288
Set owner nbkpmstr to CBL288

04/13/12 15:10:25
volume: CBL011
Remove prior owner SYSTEM from CBL011
Set owner nbkpmstr to CBL011

04/13/12 15:10:36
volume: CBL225
Remove prior owner SYSTEM from CBL225
Set owner nbkpmstr to CBL225

04/13/12 15:10:37
volume: CBL132
Remove prior owner SYSTEM from CBL132
Set owner nbkpmstr to CBL132

# 2  
Old 04-13-2012
please post what is the output you are expecting from the above input?
# 3  
Old 04-13-2012
Code:
We should only see out for the currernt date i.e 04/13/2012

Set owner nbkpmstr to CBL288
Set owner nbkpmstr to CBL011
Set owner nbkpmstr to CBL225
Set owner nbkpmstr to CBL132

# 4  
Old 04-13-2012
Code:
 
xargs -l4 <  input_file | grep `date "+%m/%d/%y"` | sed 's/.*Set/Set/'

# 5  
Old 04-13-2012
panyam,

Can you explain to me how i should enter this into the script.

Code:
xargs -l4 <  input_file | grep `date "+%m/%d/%y"` | sed 's/.*Set/Set/'


The script should read the file below looking for the current date and grab only "Set owner ". So from the example below is should grab CBL288 and not CBLJMM..

File Read - /tmp/test


Code:
$ cat /tmp/test
04/12/12 15:10:25
volume: CBLJMM
Remove prior owner SYSTEM from CBLJMM
Set owner nbkpmstr to CBLJMM

04/13/12 15:10:14
volume: CBL288
Remove prior owner SYSTEM from CBL288
Set owner nbkpmstr to CBL288

# 6  
Old 04-13-2012
Code:
substr($(NF),1,2) >= 11 {ok=1}

What is this trying to check? You're also not using DATE_1.

An awk solution could be:
Code:
awk '$1 ~ DATE1 {ok=1} ok==0 {next} /Set/ {print}' DATE1=$(date +%m/%d/%y) /tmp/test

Depending on your OS, grep may offer a 'by paragraph' or after context option you could use. e.g. with GNU grep:
Code:
export DATE_1=$(date +%m/%d/%y); grep -A4 "$DATE_1" test | grep Set

# 7  
Old 04-13-2012
Panyam

Your syntax is working, but its showing more than i require.

Code:
Set owner nbkpmstr to CBH366 04/13/12 15:16:28 volume: CBH366 Remove prior owner SYSTEM from CBH366

I only want to see

Code:
Set owner nbkpmstr to CBH366


How can i update the code to do this please

Code:
xargs -l4 <  input_file | grep `date "+%m/%d/%y"` | sed 's/.*Set/Set/'

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 check charactor in certain position?

Hi Gurus, I need to check the charactor in certain position. in my file abcdef1234gh ac1234eeeegt acdead1235gh I want to check what is check from position 7 to 10's charactor, if it is 1234, then output the whole line. for above file, I want to get below output abcdef1234gh... (2 Replies)
Discussion started by: ken6503
2 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. Shell Programming and Scripting

Find and count unique date values in a file based on position

Hello, I need some sort of way to extract every date contained in a file, and count how many of those dates there are. Here are the specifics: The date format I'm looking for is mm/dd/yyyy I only need to look after line 45 in the file (that's where the data begins) The columns of... (2 Replies)
Discussion started by: ronan1219
2 Replies

4. Shell Programming and Scripting

Need to check a file from a certain position onwards

Scripting Guru's, I need your help, can you tell me how i can check a file from a certain point onwards via a ksh script. Currerntly i am checking the whole file and can't script it so it checks from 17.01.2012 20:00:00 onwards please.. Any help will be greatly appericated. See file... (10 Replies)
Discussion started by: Junes
10 Replies

5. Shell Programming and Scripting

finding date numeral from file and check the validity of date format

hi there I have file names in different format as below triss_20111117_fxcb.csv triss_fxcb_20111117.csv xpnl_hypo_reu_miplvdone_11172011.csv xpnl_hypo_reu_miplvdone_11-17-2011.csv xpnl_hypo_reu_miplvdone_20111117.csv xpnl_hypo_reu_miplvdone_20111117xfb.csv... (10 Replies)
Discussion started by: manas_ranjan
10 Replies

6. Shell Programming and Scripting

Sort a file from specific row onwards

Hello All: I've file in below format. File name is "FIRSTN.TBL": AAAAAA N BBBBBBBBBBBBBBBBBBBBBBB N . . . . ZZZZZZZZZZZZZZZZZZZZZZZZZZ N My file row length is 40 characters and my second column will start from 25th column and it is only... (3 Replies)
Discussion started by: nvkuriseti
3 Replies

7. Shell Programming and Scripting

Extracting log entries from a date onwards

One of the log file looks like entries as below. Wed Apr 6 14:51:18 2011 FAIL LOGIN: Client "9.191.21.54" Wed Apr 6 14:52:53 2011 CONNECT: Client "9.191.21.54" Wed Apr 6 14:52:54 2011 OK LOGIN: Client "9.191.21.54" Wed Apr 6 14:55:10 2011 CONNECT: Client "9.191.21.54" Wed Apr 6... (2 Replies)
Discussion started by: rijeshpp
2 Replies

8. Shell Programming and Scripting

How to check a word position in a file ?

Hello everybody, I have a file like this : "window 1 truck 3 duck 2... fire 1... etc..." and I would like to print the following number of a word I am searching for. (For example here, if I search for the word "fire", I will print "1") Thank you for your help ! (7 Replies)
Discussion started by: tibo
7 Replies

9. Shell Programming and Scripting

check file date in one week ???

How do you write a code in ksh ?? Enter the start date: 20060228 d0 = 20060228; 2. Check for 7 days of report list 1 day after the d0 d1 = 20060301 d2 = 20060302 d3 = 20060303 d4 = 20060304 d5 = 20060305 d6 = 20060306 then cat d0.log d1.log d2.log d3.log d4.log d5.log d6.log >... (1 Reply)
Discussion started by: sabercats
1 Replies

10. UNIX for Dummies Questions & Answers

file date check script

I am creating a KSH script and need to check the filedate against the system date. I can get the sys date w. date command, and I was able to get the filedate w. the awk command but when I compare them w. an if condition statement I get syntax error. Not sure what's wrong, and other suggestions on... (4 Replies)
Discussion started by: jaxconsultant
4 Replies
Login or Register to Ask a Question