Need to check a file from a certain position onwards


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to check a file from a certain position onwards
# 1  
Old 01-18-2012
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 format below

File being checked
Code:
/usr/openv/netbackup/bin/admincmd/bplabel -o -java -m CA4140 -d hcart -p Scratchpool
CA4140 NEEDS LABELLING 17.01.2012 05:35:27
V10111 LABELED 17.01.2012 12:07:02
V10028 LABELED 17.01.2012 19:04:13
V10097 LABELED 17.01.2012 19:44:17

Check from this point onwards
Code:
/usr/openv/netbackup/bin/admincmd/bplabel -o -java -m CA5128 -d hcart -p Scratchpool 
CA5128 NEEDS LABELLING 17.01.2012 20:04:09
/usr/openv/netbackup/bin/admincmd/bplabel -o -java -m CA5129 -d hcart -p Scratchpool 
CA5129 NEEDS LABELLING 17.01.2012 20:04:09


Last edited by Franklin52; 01-18-2012 at 06:44 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-18-2012
Code:
awk ' BEGIN {ok=0}
        $(NF-1)=="17.01.2012"  &&  substr($(NF),1,2) == 20 {ok=1}
        ok==0 {next}
        {print} '   inputfile   |grep 'whatever you are looking for'

# 3  
Old 01-23-2012
Thanks Jim worked fine... But the only issue is the the string $YESTERDAY, is not being picked up properly... If i enter a data "17.01.2012" works fine...

How can i make it pick up the string, without failing please.

$(NF-1)=="17.01.2012" && substr($(NF),1,2) == 20 {ok=1}


YESTERDAY=20120122
$(NF-1)==$YESTERDAY && substr($(NF),1,2) == 20 {ok=1}
# 4  
Old 01-23-2012
You need to pass YESTERDAY as a parameter to awk
Code:
awk '{...}' YESTERDAY="20120122" inputfile | ...

HTH
--ahamed
# 5  
Old 01-23-2012
Still not picking up the informaiton



Code:
Script
 awk ' BEGIN {ok=0}
    $(NF-1)==$YESTERDAY  &&  substr($(NF),1,2) >= 15 {ok=1}
        ok==0 {next}
        {print} ' DATE1=`date +%Y%m%d` YESTERDAY=`date -d "$DATE1 last day " "+%Y%m%d"`  /usr/openv/netbackup/bin/MEDIA_DEASSIGN_CALLED.$YESTERDAY | grep label | egrep -v "MEDIA_DEASSIGN_CALLED|NEEDS LABELLING|LABELED "


Code:
OUTPUT 
+ egrep -v 'MEDIA_DEASSIGN_CALLED|NEEDS LABELLING|LABELED '
+ awk $' BEGIN {ok=0}\n    $(NF-1)==$YESTERDAY  &&  substr($(NF),1,2) >= 15 {ok=1}\n           ok==0 {next}\n        {print} ' DATE1=20120123 YESTERDAY=20120122 /usr/openv/netbackup/bin/MEDIA_DEASSIGN_CALLED.20120122

# 6  
Old 01-23-2012
Do not use "$" with YESTERDAY... use it like this $(NF-1)==YESTERDAY

And your file seems to have date with dotted notation and the date you are passing to awk is without dots.

--ahamed
# 7  
Old 01-23-2012
Removed $, made no differnce....

Doesn't seem it being passed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk - $9 and onwards

How can I get awk to print all fields from $9 and onwards? (2 Replies)
Discussion started by: locoroco
2 Replies

2. Shell Programming and Scripting

Script to count matched string then check again from last read position

Hi all, I am currently trying to figure out how can i capture a particular string from a log file, then search again but from the last line it read before onward. Basically let's say that the check runs every 5 mins via cron, counting the number of matched strings "Cannot assign requested... (5 Replies)
Discussion started by: nms
5 Replies

3. 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

4. Shell Programming and Scripting

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 awk '... (9 Replies)
Discussion started by: Junes
9 Replies

5. 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

6. UNIX for Dummies Questions & Answers

Using grep to check for character at fixed position

i have a file (test.txt) that contains: 20799510617900000928000000005403020110315V 20799510617900000928000000005403020110316 20799510617900000928000000005403020110317 20799510617900000928000000005403020110318V grep V test.txt > /tmp/void.log if then mail -s "void" < test.txt fi... (2 Replies)
Discussion started by: tjmannonline
2 Replies

7. Shell Programming and Scripting

Moving first position in a file to the last position

hi, I have a file which consists of some records: 2010_06_4010093_001_001|10|ABCDEFGH|9|4010093||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00001| 2010_06_4010162_001_001|11|ABCDEFGH|9|4010162||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00002|... (11 Replies)
Discussion started by: pparthiv
11 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 position of end of line(URGENT PLS)

I Have to check in a file that all the lines are ending at same posiotin. Ex : line 1 is ending at position 88 line 2 should at same position i.e 88 Thanks in advance (6 Replies)
Discussion started by: evvander
6 Replies

10. Shell Programming and Scripting

check position of end of line for some specific lines

-------------------------------------------------------------------------------- Have to check in a file that the lines starting with 620 and 705 are ending at same posiotin. 82012345 62023232323 70523949558 62023255454 9999 In the above lines, i have to check the lines starting... (1 Reply)
Discussion started by: senthil_is
1 Replies
Login or Register to Ask a Question