Issue
So I am currently reading from this txt file:
Line 961: www-d1.proxy.aol.com - - [01/Aug/1995:00:35:32 -0400] "GET /elv/hot.gif HTTP/1.0" 200 1007
Line 965: www-d1.proxy.aol.com - - [01/Aug/1995:00:35:41 -0400] "GET /elv/PEGASUS/minpeg1.gif HTTP/1.0" 200 1055
Line 966: www-d1.proxy.aol.com - - [01/Aug/1995:00:35:46 -0400] "GET /elv/SCOUT/scout.gif HTTP/1.0" 200 1165
Line 969: www-d1.proxy.aol.com - - [01/Aug/1995:00:35:49 -0400] "GET /elv/DELTA/delta.gif HTTP/1.0" 200 2244
Line 972: www-d1.proxy.aol.com - - [01/Aug/1995:00:35:51 -0400] "GET /elv/ATLAS_CENTAUR/atlas.gif HTTP/1.0" 200 2286
Line 95219: u139.n72.queensu.ca - - [04/Aug/1995:10:40:04 -0400] "GET /elv HTTP/1.0" 302 -
And I am trying to print out only the names in the command line(basically only the ones in capital letters) WITH NO DUPLICATES. For example:
ATLAS_CENTAUR
DELTA
SCOUT
PEGASUS
My codes so far:
grep "/elv" ~/spacestation.txt | awk -F/ '{print $5}' | sort -u
Actual output:
1.0" 302
ATLAS_CENTAUR
DELTA
hot.gif HTTP
SCOUT
PEGASUS
Solution
You need to put regex pattern in your awk script to compare $5:
Solution:
grep "/elv" ~/spacestation.txt | awk -F/ '$5 ~ /^[A-Z_]+/ {print $5}' | sort -u
- '~' is for compare $5 with regex pattern matching
- '^' is first character of word
- '[A-Z_]' will look for all caps-lock characters including with _
- '+' is for to continue with matching [A-Z_] if he finds one or more character like this
Answered By - acakojic Answer Checked By - Marie Seifert (WPSolving Admin)