• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just use a grep -e with regular expressions?
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vaidas Kve
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 280
VI Editor C++ Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic