aspose file tools
The moose likes Linux / UNIX and the fly likes Grep.Need help with finding the words which start at [A-K] letters in the third column of the table Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Reply Bookmark "Grep.Need help with finding the words which start at [A-K] letters in the third column of the table" Watch "Grep.Need help with finding the words which start at [A-K] letters in the third column of the table" New topic
Author

Grep.Need help with finding the words which start at [A-K] letters in the third column of the table

Vaidas Kve
Greenhorn

Joined: Apr 27, 2012
Posts: 2
Hi buddies ! I need some help with one grep command I have this table:

1 Petras Pavardenis 1980 5
08 Linas Bajoriunas 1970 10
3 Saulius Matikaitis 1982 2
5 Mindaugas Stulgis 1990 7
6 Rimas Nasickis 1964 10
7 Simas Saulenis 1966 12
8 Justas Skukauskas 1995 9
9 Petras Petronkus 1988 3
10 Zanas Baltraitis 1990 5
11 Mantas Tutkus 1974 1
12 Edmundas Butkus 1970 9
13 Mindaugas Sinkevicius 1945 11
14 Edgaras Zvironas 1930 8
15 Vaidas Gaubas 1985 12
16 Gintaras Gintaitis 1980 5
17 Raigardas Tautkus 1975 1
18 Darvydas Tautkevicius 1925 12
19 Tomas Cereska 1989 4
20 Saulius Sidlauskas 1984 6
21 Jonas Jonaitis 1966 8
22 Jonas Petraitis 1940 12
23 Jonas Ringys 1970 1
13 Julius Jonaitis 1974 11

And i need to find the words which start with capital letters A,B,C,D,E,F,G,H,I,J,K in the column 3 (the first word of this column is "Pavardenis") . Not in all columns but just in the third column (as I said earlier the first word of this column is "Pavardenis"). And i must use only GREP command (I cannot use awk or other commands due to my school restrictions).
alex yarm
Greenhorn

Joined: Apr 28, 2012
Posts: 5
just use a grep -e with regular expressions?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5541

Please see this: NotACodeMill
Show us what you have so far and tell us what results you are getting so far. We will then be happy to answer specific questions or offer specific pointers.


JBoss In Action
Vaidas Kve
Greenhorn

Joined: Apr 27, 2012
Posts: 2
I found the solution. This is the solution of my problem: command: egrep '^.{4}.*[A-K]' filename number 4 means the amount of ignored spaces (columns) including tabs and space Thanks for your help
Anand Hariharan
Rancher

Joined: Aug 22, 2006
Posts: 252

Try awk (or its variants)

awk '$3 ~ /^[A-K]/' {print}' file

Methinks the command line is readable to an extent that it almost paraphrases your subject (except that it uses awk instead of grep).


Also, hope you are aware that your grep solution uses the greedy .* that follows a .{4}. I suppose that works for your input. A slightly better (i.e., more expressive) grep solution would be

grep '^[^A-Z]*[A-Z].*[A-K]' file

It is basically looking for the string that has one (any) upper case letter followed by one or more arbitrary character(s) followed by one upper case between A through K.

[Edit: Sorry, didn't realise (1) this was homework (2) that you were precluded from using awk. Peter's response was the correct one.]


"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Grep.Need help with finding the words which start at [A-K] letters in the third column of the table
 
Similar Threads
HashSet Magic
how this setOut method works.......
prime number problem
Generate random id on an html page
Try these games...