any way to squish several date options into one line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting any way to squish several date options into one line?
# 1  
Old 05-26-2009
any way to squish several date options into one line?

this obviously isnt overly important, but its a bit slow and i was wondering if i could prevent it from re-searching the file several times. i want my matches from the previous and coming three days, as well as today. this is what i have but its weighty and im having trouble finding a way to slim it down.

cd ~/work
grep -iT `date --date="3 days ago" "+%b%d"` les
grep -iT `date --date="2 days ago" "+%b%d"` les
grep -iT `date --date="1 days ago" "+%b%d"` les
grep -iT `date "+%b%d"` les
grep -iT `date --date="next day" "+%b%d"` les
grep -iT `date --date="2 days" "+%b%d"` les
grep -iT `date --date="3 days" "+%b%d"` les

just need to spit out the lines starting with mmmdd, and im hoping to save some space/time.
thanks
nomkev
# 2  
Old 05-26-2009
show sample of your file
# 3  
Old 05-26-2009
thats it. its just a function... i skipped the {} to save space.

edit: oops. the file. well it has names, but its basically a txt with:

may24 name name
may25 name name
may26 name name
etc...

edit again: single digits are in the 'may01' etc

Last edited by nomkev; 05-26-2009 at 11:42 AM..
# 4  
Old 05-26-2009
This following should be quicker...

Code:
gawk '
   BEGIN {
     for (i=-3;i<=3;i++)
     {
        cmd="date --date=\"" i "days\" \"+%b%d\""
        cmd | getline
        close(cmd)
        dy[$0]++
     }
   }
   { for (s in dy) if ($0 ~ "^" s "[^0-9]") print }' les

# 5  
Old 05-26-2009
im getting no output...
changed gawk to mawk (im using ubuntu) but no errors either.
# 6  
Old 05-26-2009
I didn't spot that you were ignoring case in your grep commands. Changes in bold red:

Code:
gawk '
   BEGIN {
     for (i=-3;i<=3;i++)
     {
        cmd="date --date=\"" i "days\" \"+%b%d\""
        cmd | getline
        close(cmd)
        dy[tolower($0)]++
     }
   }
   { for (s in dy) if ($0 ~ "^" tolower(s) "[^0-9]") print }' les

# 7  
Old 05-26-2009
beautiful, and much faster.
thanks alot!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX Date function with -d options

Hi , I couldn't understand how this program works. Can somebody please explain it to me. DT=`date -d "1 day"` # This part I understand echo ${DT/ */} # How this works echo ${DT/* /} (2 Replies)
Discussion started by: LoneRanger
2 Replies

2. Shell Programming and Scripting

Processing Multiple Arguments in Command Line Options

Hi All, I am new to scripting. Could you please assist me . Here is my requirement. I have written a script that has 2 option flags defined. -l) calls some function with the arguments passed in front of -l -r) calls second function with the arguments passed in front of -r *) calls the... (7 Replies)
Discussion started by: Jay Deshpande
7 Replies

3. Shell Programming and Scripting

Shell script to read multiple options from file, line by line

Hi all I have spent half a day trying to create a shell script which reads a configuration file on a line by line basis. The idea of the file is that each will contain server information, such as IP address and various port numbers. The line could also be blank (The file is user created). Here... (1 Reply)
Discussion started by: haggismn
1 Replies

4. Shell Programming and Scripting

awk script file command line options

Being new to awk I have a really basic question. It just has to be in the archives but it didn't bite me when I went looking for it. I've written an awk script, placed it in a file, added the "#!/usr/bin/awk -f" at the top of the script and away I go. "% myAwk <inputfile>" gives me exactly what... (2 Replies)
Discussion started by: tomr2k
2 Replies

5. Shell Programming and Scripting

Issue with spaces in Java command line options

Hi, I am writing a shell script to build Java options dynamically in a variable array and pass them to java.exe. If an option value contains a space, I cannot find a way to get it interpreted correctly. Here is my example: #!/bin/bash JAVA_HOME=/opt/jvm/jre1.5.0_18 JAVA_OPTS=("-Xms256m... (4 Replies)
Discussion started by: Romain
4 Replies

6. Shell Programming and Scripting

Run perl script, with command-line options

Hello everyone, I have a perl script which takes various command line options from user like : test.pl -i <input_file> -o <output_file> -d <value> -c <value> Now I have multiple input files in a directory: <input_file_1> <input_file_2> <input_file_3> <input_file_4> ..... .... ...... (6 Replies)
Discussion started by: ad23
6 Replies

7. Shell Programming and Scripting

Using perl to get options from command line

Hi all, I want to get options from command line by perl. usage() options: -h Show this help message and exit -t Name of tester --timeout Set the timeout -l ... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

8. Shell Programming and Scripting

Associated array from command line options

I am looking to populate an (associated) array with a command line argument. The command line would look something like this: alert -action test -priority '10' -module test_module . . . The associated array would look like this after the data is read in flag=(action=test priority=10... (1 Reply)
Discussion started by: jperret
1 Replies

9. Programming

Executing command line options

Can someone please tell me how to modify/add to this code so that it recognizes UNIX command options (all beginning with "-") and executes the command with options? #include<stdio.h> #include<stdlib.h> int main(int argc, char *argv) { int i; system("stty -echo"); ... (8 Replies)
Discussion started by: Safia
8 Replies
Login or Register to Ask a Question