Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print only words with Capital Letters (Linux)

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
like image 603
Kinja Avatar asked Oct 20 '20 17:10

Kinja


People also ask

How do you grep a capital letter?

grep -c '[A-Z]' exatext1 then this will only tell you how many lines there are in exatext1 that contain words with capital letters. To know how many words there are with capital letters, one should carry out the grep -c operation on a file that only has one word from exatext1 per line: grep -c '[A-Z]' exa_words .

How do you grep upper and lower case?

By default, grep is case sensitive. This means that the uppercase and lowercase characters are treated as distinct. To ignore case when searching, invoke grep with the -i option (or --ignore-case ). Specifying “Zebra” will match “zebra”, “ZEbrA” or any other combination of upper and lower case letters for that string.

Does Linux need to be capitalized?

Linux is a word-mark, meaning that any form of the word is covered by the trademark registration. This includes all-caps (“LINUX®”) or the standard capitalized form (“Linux®”). Either form is acceptable to the Linux Foundation so long as it is presented in a legible font.


1 Answers

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 
  1. '~' is for compare $5 with regex pattern matching
  2. '^' is first character of word
  3. '[A-Z_]' will look for all caps-lock characters including with _
  4. '+' is for to continue with matching [A-Z_] if he finds one or more character like this
like image 106
acakojic Avatar answered Sep 20 '22 01:09

acakojic