Find and awk with today's date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and awk with today's date
# 8  
Old 01-27-2015
Hi Chubler,

Just received your message and will try this tomorrow at work.. I saw that FILENAME and after reading about it knew it would be applied some where some how.

thanks

I will let you know how it comes out.

regards
al

---------- Post updated 01-27-15 at 08:49 AM ---------- Previous update was 01-26-15 at 07:03 PM ----------

Good Morning Chubler,

Just a note to say "THANKS!" for your help in this effort. The suggestion worked as it was supposed to without changing awk to nawk. Your effort will all me to create the metric now on a spread sheet tracking those databases that are having connections refused on a daily basis via server. In the string is the db name I change the names to protect the innocent as they say. I can say though it was a Navy program that you had a hand in helping keeping our servicemen/women paid on time and ships in good repair.

Again thanks,

al

---------- Post updated at 11:32 AM ---------- Previous update was at 08:49 AM ----------

Morning Chubler,

Just a quick question. I was trying to understand a section of the code and can't seem to find any information on it.

{F++} END{ if(F) print FILENAME":"F}

Can you briefly explain the F++ and the F means in this code? Can you recommend a good book to read on learning this subject?

It would be appreciated.

thanks

al
# 9  
Old 01-27-2015
You are most welcome. Glad to hear the updated program is making your life easier.

I'll try and explain that code segment.

Firstly F has now special meaning and I picked the variable F to represent "Found". It's quite common here to use short variable names but for you own benefit later down the track I'd suggest using LinesFound or something like that.

F++ Has it's roots in the C programming language it increments the variable and could be also written as F=F+1 in basic and many other languages. Note if F is uninitialized (as in on the first matching line) it will be set to 1 by this command.

END{ if(F) print FILENAME":"F} The END condition is a special awk condition and only applies once after the all files have been processed. In this block we are testing our F variable and if it is non-zero we print the input file name followed by a colon character ":" and the F variable's value. This is to avoid printing "filename:" when no lines are found.
# 10  
Old 01-28-2015
Morning,

I will put your explanation in my note book.

That is what I was surmising but wasn't sure. I am some what familiar with programming but never really had a chance to get my head into it. It was great working with you.

Regards

al
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare Date to today's date in shell script

Hi Community! Following on from this code in another thread: #!/bin/bash file_string=`/bin/cat date.txt | /usr/bin/awk '{print $5,$4,$7,$6,$8}'` file_date=`/bin/date -d "$file_string"` file_epoch=`/bin/date -d "$file_string" +%s` now_epoch=`/bin/date +%s` if then #let... (2 Replies)
Discussion started by: Greenage
2 Replies

2. UNIX for Beginners Questions & Answers

Find and copy .zip file based on today's date

Hi Team, I'm new to unix and i have a requirement to copy or move files from one directory to another based on current date mentioned in the .zip file name. Note that i need to copy only the recent zip file. please help me with the code i tried the code as: #! /usr/bin/sh find... (3 Replies)
Discussion started by: midhun3108
3 Replies

3. Shell Programming and Scripting

Check, if date is not today

hello, in a file exist entries in date format YYYYMMDD. i want to find out, if there are dates, which isn't today's date. file: date example text 20140714 <= not today's date 20140715 <= not today's date 20140716 <= today's date my idea is to use Perderabo's datecalc ... (2 Replies)
Discussion started by: bora99
2 Replies

4. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

5. Shell Programming and Scripting

Need to add a date column (today's date) in file

Hi I have file with number status and date1 and date1 field, want add a column today between column date1 and date2. file1.txt number status date1 date2 ===== ==== === ===== 34567 open 27/06/13 28/06/13 45678 open 27/06/13 28/06/13 43567 open 27/06/13 28/06/13 ... (1 Reply)
Discussion started by: vijay_rajni
1 Replies

6. Shell Programming and Scripting

UNIX date fuction - how to deduct days from today's date

Hi, One of my Unix scripts needs to look for files coming in on Fridays. This script runs on Mondays. $date +"%y%m%d" will give me today's date. How can I get previous Friday's date.. can I do "today's date minus 3 days" to get Friday's date? If not, then any other way?? Name of the files is... (4 Replies)
Discussion started by: juzz4fun
4 Replies

7. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

8. Shell Programming and Scripting

Find file that matches today's date in filename and move to /tmp in bash

I'm having problems with my bash script. I would like to find a file matching today's date in the filename, i.e. my_file_20120902.txt and then move it to a different directory, i.e. /tmp. Thanks. (1 Reply)
Discussion started by: jamesi
1 Replies

9. UNIX for Dummies Questions & Answers

Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete

Hello, I am trying to show today's date and time in a better format than ‘date' (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks... (3 Replies)
Discussion started by: citizencro
3 Replies

10. UNIX for Dummies Questions & Answers

compare today's date with date in a file

Hi I am very new to scripting, Can someone show me how to (in unix shell script) compare the system's date with a date in a file. The requirement is to somehow open this file (which will only have a date in it) and compare it with today's date. If they are equal execute a procedure below but if... (4 Replies)
Discussion started by: siog
4 Replies
Login or Register to Ask a Question