Grep command issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep command issue
# 1  
Old 02-12-2012
Grep command issue

How am I supposed to print with one Unix command the names (and only the names) of company JMT? Problems with scandinavian letters? By typing

Code:
grep JMT url | egrep --only-matching '[^[:digit:]]+'

I still have company name and + marks I should get rid of.

I'd be very grateful of your help bacause I am new to this.

Code:
    [Name]                  [Company]
1. Matti Meikäläinen               TTK               36.9
2. Teemu Aho                       JMT               37.0  +0.1
3. Kaarna Käyrä                    JMT               37.1  +0.1
4. Maija Meheväv                   TTK               37.2  +0.1
5. Giglio Matjusha                 JMT               37.3  +0.1


Last edited by methyl; 02-12-2012 at 07:04 PM.. Reason: please use code tags... tidied layout a bit
# 2  
Old 02-12-2012
It is not that straightforward, because names are perhaps not always only 2 words and what is trailing might vary as well.
This might work:
Code:
sed '1d;s/[^ \]*[ \t]//;s/[ \t][[:upper:]]\{2\}.*//' infile

Just JMT would be:
Code:
sed '1d;/JMT/!d;s/[^ \]*[ \t]//;s/[ \t][[:upper:]]\{2\}.*//' infile

-or a somewhat complicated field separator-
Code:
awk -F'[ \t][[:upper:]]{2}|[0-9]+\.[ \t]+' 'NR>1&&/JMT/{print $2}' infile

-if Finnish names are always two words:
Code:
awk 'NR>1 && /JMT/{print $2,$3}' infile


Last edited by Scrutinizer; 02-12-2012 at 07:59 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue executing grep command on Solaris

more jdbc.xml <name>Fast_ds/DataSource</name> <property> <name>user</name> <value>COL_USER</value> </property>Command 1: grep -A1 '<name>user</name>' jdbc.xml|grep -v '<name>user</name>'|sed 's/\(<value>\|<\/value>\)//g'| sed -e 's/^*//'Output: Command 2: grep... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. Shell Programming and Scripting

Issue using empty variable in grep command

Hi, I'm writing a shell script and trying to grep a variable value, it works fine as long as there is a value in /tmp/list.out which is captured in $DSK but sometimes the file tends to be empty and that is where I'm having an issue while using grep which returns nothing. I know I can use something... (15 Replies)
Discussion started by: mbak
15 Replies

3. UNIX for Dummies Questions & Answers

Grep issue

HI, I have a command to check a license file. License_print. In that file you get the headlines and all different licenses. Now i want to have things extracted from it. so i do like following: license_print | grep -iw -e "user" -e "admin" But i don´t want all lines where user is... (11 Replies)
Discussion started by: Tzwaj
11 Replies

4. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

5. Shell Programming and Scripting

Issue in grep

i have following pattern in file s6:s2 s2:s4 s1:s2:s3:s4:s5:s6 s1 . . Now i want to find occurence of each record in file like s6:s2 occurs twice {once in first record and both occur in 3 record as well} so output should be s6:s2 2 s2:s4 2 s1:s2:s3:s4:s5:s6 :1 s1 : 2 ... (7 Replies)
Discussion started by: sharad.40216
7 Replies

6. Shell Programming and Scripting

GREP ISSUE

Hi im trying a GREP a varaiable which contains a file name and i search it in a list of .txt file and ifs its found the .txt file , it returns the name of the txt file name..the snippet im using is foreach my $files (glob('*.txt')) { open(my $fh1, $files) or die("Unable to open '$files':... (2 Replies)
Discussion started by: rajkrishna89
2 Replies

7. Shell Programming and Scripting

CUT Command and grep issue

I am trying to grep the oracle erros evry day from the logs file. My problem is : -rw-r----- 1 tibcolm tibco 17438361 Apr 5 11:59 RetryService-RetryService.log -rw-r----- 1 tibcolm tibco 245303 Apr 5 12:00 ResponseService-ResponseService.log -rw-r----- 1 tibcolm tibco 2122654 Apr 5 12:00... (4 Replies)
Discussion started by: neeraj617
4 Replies

8. HP-UX

Performance issue with 'grep' command for huge file size

I have 2 files; one file (say, details.txt) contains the details of employees and another file (say, emp.txt) has some selected employee names. I am extracting employee details from details.txt by using emp.txt and the corresponding code is: while read line do emp_name=`echo $line` grep -e... (7 Replies)
Discussion started by: arb_1984
7 Replies

9. UNIX for Dummies Questions & Answers

Grep issue

more Hello.txt it was a sunny way and i was about to go home. I need to grep and redirect to a new file all the text between 'sunny' and 'go' string above. Note: There may be multiple lines in between the string i need to grep between. If there are multiple 'go' strings it should grep till... (9 Replies)
Discussion started by: mohtashims
9 Replies

10. Shell Programming and Scripting

issue with grep command

i am using 'psu' to grep the status of a process like below :- psu|grep -i agentf 29559 29552 0 00:53:05 ? 0:57 gn1avm_agent -n AGENTF1 28946 1 0 00:51:31 ? 0:31 gnavm_ewd -b gn1avm_agent -n AGENTF1 -c -n AGENTF1 29552 28946 0 00:53:05 ? 0:00 /bin/ksh... (6 Replies)
Discussion started by: deepakiniimt
6 Replies
Login or Register to Ask a Question