Not sure if the title of this thread makes sense, but hopefully my explanation will.
I'm using awk to print some stats from an apache accesslog. I would like to specify the regexp condition where only the two root pages of "index.html" and "/" are counted in my results. What I can't figure out is how, using regexp or otherwise, I can specify that I only want the forwardslash entries counted ONLY if the forwardslash is at BOTH the start and end of the line....in otherwords, it's the ONLY character on that line. Here's what I have that I thought would work but isn't:
I suppose I can't expect the machine to interpret my placing ^ and $ next to one another to mean "this string is at the beginning AND end of the line".
It'd be better if you post some sample of your data, in the meantime to retrieve / count the lines that start and end with a forward slash, you can try this,
Thanks for the direction. Here are a few lines (field 7 only) of the accesslog I'm working with:
/ (count lines like this one)
/index.html (count lines like this one)
/
/
/portals/index.html (don't want lines like this one counted)
/family_medicine/index.html
/
/
/portals/pda/ (don't want lines like this one counted)
/portals/surgery/
/portals/pediatrics/
Where each line that contains "/" and "/index.html" are the only lines I'm interested in. Note: I'm only interested in the root level index.html not the cases like "/portals/index.html".
Using your code, I'm not finding any matches. When trying just one of the conditions, such as:
it works fine-- I'm showing a count of 5 hits on "/index.html". However, when I try your example of combining the two conditions, that's where I'm not getting any results at all. If I try ONLY your added condition (awk '$7 ~ /\/$/ {print $7}' ....), I get results including lines such as "/portals/pediatrics/" which I don't want.
The AND/OR logic is a touch confusing for me here because I definitely want the count incremented for BOTH conditions, but by using AND it's not going to take it that I mean that field 7 must contain BOTH "/" and "/index.html" per line will it? Obviously OR may not apply here because I don't want it choosing between the two conditions-- I want them both counted.
I hope this clarified and didn't complicate! thanks again.
Derek
Last edited by picassolsus; 08-20-2008 at 03:50 PM..
Hi, In my previous post ( How to print lines from a files with specific start and end patterns and pick only the last lines? ), i have got a help to get the last select statement from a file, now i need to remove/exclude the output from main file:
Input File format:
SELECT
ABCD,
DEFGH,... (2 Replies)
Hi,
I have a scenario where I want to display the output based on the pattern search between the start and end of a block in a file, we can have multiple start and end blocks in a file.
Example give below, we need to search between the start block abc and end block def in a file, after that... (5 Replies)
My file (the output of an experiment) starts off looking like this,
_____________________________________________________________
Subjects incorporated to date: 001
Data file started on machine PKSHS260-05CP
**********************************************************************
Subject 1,... (9 Replies)
I have a list of countries and I'm trying to print the country names that start with "A" and end in "a".
I can do the first one which gives me the correct output.
awk '/^A/ {print $1}' countries.txt
but when I try:
awk '/^A a$/ {print $1}' countries.txt
or even:
awk... (2 Replies)
I have a file as follows:
0
1056
85540
414329
774485
1208487
1657519
2102753
2561259
3037737
3458144
3993019
4417959
4809964
5261890
5798778
6254146
I want to find all lines between a specified start and end tag. (6 Replies)
Hello fellow awkers and seders:
need to figure out a way to ensure a software deployment has completed by checking its trace file in which I can store the deployment results as follows:
echo $testvar
===== Summary - Deploy Result - Start ===== ===== Summary - Deploy Result - End =====... (1 Reply)
Hi,
I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
How can I do this? Actually I have a file which contains a path
e.g.
/home/john/Music/hello.mp3
and I want to take only the filename (hello.mp3) So, I need to read the file from its end to its start till the character "/"
Is this possible?
Thanks, I am sure you'll not disappoint me here!
Oh,... (9 Replies)
Hi ,
I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;"
... (4 Replies)
Hi
i had String like
UID: ABC345QWE678GFK345SA90, LENGTH 32
when I used awk ' FS, {print $1}' prints
ABC345QWE678GFK345SA90,
how can i getrid of that coma at the end of the string.
Thanks in advance.. (14 Replies)