How to use xargs to repeat as a loop to grab date string?
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
My goal to find how many requests in 14 days from weblog server. I know to cat a weblog file to wc -l to find the total of all requests have send to server. From there on, I can use a loop of 14 days to go through each line and do comparison with Date String until the string are different I would increment the date until it reach 14th date. I was thinking to seq 14 and xargs commands to go through 14 days cycle.
I would like to know how to do a string compare between date?
I'm deliberately posting the following command for various reasons:
To prove that OP's idea might work under certain/ideal circumstances (non-strict accuracy eg. (roughly) to a day, it's the second half of the month etc.)
To show the OP that the logic is flawed
The professor won't accept this anyway
This works and it's counting lines for timestamps from 24/Nov/2014 to 10/Nov/2014 (last 14 days).
Now imagine it's Nov 5 ...
Following hints should help you to do it right and to gain an accuracy to a second:
1. Get the last line of access.log (newest entry)
2. Cut the date-time-timezone stamp (10/Jun/2013:07:43:40 -0700)
3. Reformat above string to something you can feed to GNU date, e.g. 2013-06-10 07:43:40 OR 2013/06/10 07:43:40 OR 20130610 07:43:40 OR whatever
4. Using GNU date, convert the reformatted string to seconds since 1970-01-01
4.1 Subtract 60×60×24×14 seconds (14 days) from the result and put the result in a variable, eg. twoweeksago
6. In a while loop you then parse the access.log file line by line
6.1. You repeat the steps 2, 3 and 4 here
6.2. Pseudo code: if seconds greater than/equal to twoweeksago then increment counter
7. echo "$counter requests"
Hope this helps.
This User Gave Thanks to junior-helper For This Post:
I have tried the approach to grep the date of the last line and cut out the Date field and I have problem of getting rid of the square bracket.
How do I remove the square bracket from most left? I have tried to use grep but
Unsuccessful to get rid of the bracket. After removed the bracket I think I can use
date "14 days ago" to set a stop point where I can count for all requests between those
date. I hope I got the right approach from here.
> I have tried the approach to grep the date of the last line
You don't need to cat the whole file to get the last line. Try
It will retrieve only the very last line and apply the cut command to it.
Quote:
> and I have problem of getting rid of the square bracket.
> How do I remove the square bracket from most left?
You could simply add | cut -c2- to the above command. It will cut from the second character on until the end of the line, thus removing the square bracket.
In a loop, the above really should be done by making use of bash's built-ins for better performance.
Example:
Quote:
> I think I can use date "14 days ago" to set a stop point
In the file below I am trying to count the given repeats of A,T,C,G in each string of letters. Each sequence is below the > and it is possible for a string of repeats to wrap from the line above. For example, in the first line the last letter is a T and the next lines has 3 more. I think the below... (10 Replies)
Hi all,
I'm struggling with this task and have done alot of googling but not found the solution or atleast not found a way to combine them, i'm hoping someone here can help me out.
I have a file that contains many line of config "below is two lines for an example"
323 => 1111,Terry berry... (3 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. How can i use loop to repeat task.
2.shirt=15
black=13.50
echo "how many shirt you want"
read num
echo
echo "Please enter a choice"
echo "1 ---> normal... (5 Replies)
Hello there! I'm having a lot of trouble writing a script.
The script is supposed to:
1) Find all files with the name "Object.mtl" within each folder in the directory: /Users/username/Desktop/convert/Objects
2) Search and replace the string ".bmp" with ".tif" (without the quotations)
3)... (1 Reply)
I have a file like this
2011-10-10 10:46:00,1-1-13-1-1,151510,ALCLA0A84D2C
2011-10-10 10:46:00,1-1-13-1-1,151520,65537
2011-10-10 10:46:00,1-1-13-1-1,151515,46932
2011-10-10 10:46:00,1-1-13-1-1,151521,32769
2011-10-10 10:46:00,1-1-13-1-1,151522,32769
2011-10-10... (4 Replies)
Hello Unix gurus,
I have a gzipped file where each line contains 2 street addresses in the US. What I want to do is get a count for each state that does not match.
What I have so far is:
$ gzcat matched_10_09.txt.gz |cut -c 106-107,184-185 | head -5
CTCT
CTNY
CTCT
CTFL
CTMA
This cuts... (5 Replies)
In a shell script, I need to grab the first or second line after a search string in a file. For example:
File.out:
Random Info
Manufacturer: XYZPDQ
System Info
Manufacturer: Hewlett-Packard
Product Name: ProLiant
I search for the word FILE, I want to be able to grab the line... (1 Reply)
1. The problem statement, all variables and given/known data:
I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format .
I have developed a log analysis command line utility that displays... (1 Reply)
I'm trying to get a case statement to start over if an undefined option is selected... But I am ata loss on how to actually do it.
Here is a quick example of what I have.
Echo "1) do this/n
2) Do that/n
3) Quit/n
Make a selection/n"
Read answer
Case answer in
1) Dothid;;
2) Dothat;;... (3 Replies)
What I'm trying to do is perform a copy, well a ditto actually, on the results of a find command, but some inline string substitution needs to happen.
So if I run this code find ./ -name "*.tif" I get back these results.
.//1234567.tif
.//abcdefg.tif
Now the action from exec or xargs I... (2 Replies)