Extract match cases


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract match cases
# 8  
Old 03-17-2012
I learned AWK from different tutorial in my native language Smilie. But you can be safe about the link I gave you. It has everything you need to start learning AWK and it is written in a very simple and explanatory way. After you go through this manual, you should be able to understand the code I gave you for your problem Smilie.
This User Gave Thanks to bartus11 For This Post:
# 9  
Old 03-17-2012
Quote:
Originally Posted by bartus11
I learned AWK from different tutorial in my native language Smilie. But you can be safe about the link I gave you. It has everything you need to start learning AWK and it is written in a very simple and explanatory way. After you go through this manual, you should be able to understand the code I gave you for your problem Smilie.

thx man but can you tell me a bit about
'/@/{m=$0;p=0}/ and
/{p++}
it was interesting for me !

# 10  
Old 03-17-2012
/@/{m=$0;p=0}/: if line contains "@", then assign it into variable "m" (in other words assign email address to variable "m") and clear variable "p".
p++ is incrementing variable "p" if condition is met.
This User Gave Thanks to bartus11 For This Post:
# 11  
Old 03-17-2012
thx man according to your guidance you start your counter with p=0 and when it passes every condition it increases with p++ like p=p+1 and finally if all condition were true your counter has reached 3 according to that we print m and if it wasn't equal to we don't print m .

is that right ?
# 12  
Old 03-17-2012
Quote:
Originally Posted by mhs
thx man according to your guidance you start your counter with p=0 and when it passes every condition it increases with p++ like p=p+1 and finally if all condition were true your counter has reached 3 according to that we print m and if it wasn't equal to we don't print m .

is that right ?
Yes.
This User Gave Thanks to bartus11 For This Post:
# 13  
Old 03-17-2012
thx man thx for your great help

another question is if our first line was like "first1@xyz.com Sam,jones"
how can we select only mail address
i think we should pipe our stdout to cut command


and how awk can finds that every
Argument like our creation date and POP3 Last Login Date is in a new line or next line and how can our counter back to zero after 4 line

because it wasnt like
for i in `cat file` do ; .....;done


# 14  
Old 03-17-2012
If email address is always in the first field, then just change m=$0 to m=$1. As for the reseting the counter.. It is done when email address is found on the line, so each counter is "private" for particular email address.
This User Gave Thanks to bartus11 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Match file and extract the output

Hi All I have 2 file . I need match the files based on key and then form a third file which have the matching values FILE1: 10264;K*AD 10265;K*AIR 10266;K*AUTO 10267;K*BABY 10268;K* FOOD FILE2: 10264;1055.83 10265;716.94 10267;331.80 10268;23283.33 OUTPUT (Needed)... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

2. UNIX for Beginners Questions & Answers

Help with pattern match and Extract

Hi All, I am having a file like below . Basically when SB comes in the text with B. I have to take the word till SB. When there only B I should take take till B. Tried for cut it by demilter but not able to build the logic SB- CD B_RESTO SB_RESTO CRYSTALS BOILERS -->There SB and B so I... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

3. Shell Programming and Scripting

Match and extract data using two files

Hello, Using the information in file 1, I would like to extract from file2 all rows which matchs in column 3. file 1 1233 1230 1231 1232 file2 65733.00 19775.00 1220 65733.00 19793.00 1220 65733.00 19801.00 1220 65733.00 19809.00 1231 65733.00 19817.00 ... (2 Replies)
Discussion started by: jiam912
2 Replies

4. Shell Programming and Scripting

How to extract next n characters after a match is found?

Hi, I want to extract the next 7 characters after I encounter the first ( in the code eg abc123=(xvn1342) xyz678123=(ret8901) I want to extract xvn1342,ret8901. Please advise how to achieve this with awk, if possible? (9 Replies)
Discussion started by: sidnow
9 Replies

5. Shell Programming and Scripting

Extract lines that match a pattern

Hi all, I got a file that contains the following content, Actually it is a part of the file content, Installing XYZ XYZA Image, API 18, revision 2 Unzipping XYZ XYZA Image, API 18, revision 2 (1%) Unzipping XYZ XYZA Image, API 18, revision 2 (96%) Unzipping XYZ XYZA Image, API 18,... (7 Replies)
Discussion started by: Kashyap
7 Replies

6. Shell Programming and Scripting

Pattern Match & Extract from a string

Hi, I have long string in 2nd field, as shown below: REF1 | CLESCLJSCSHSCSMSCSNSCSRSCUDSCUFSCU7SCV1SCWPSCXGPDBACAPA0DHDPDMESED6 REF2 | SBR4PCBFPCDRSCSCG3SCHEBSCKNSCKPSCLLSCMCZXTNPCVFPCV6P4KL0DMDSDSASEWG I have a group of fixed patterns which can occur in these long strings & only... (11 Replies)
Discussion started by: karumudi7
11 Replies

7. Shell Programming and Scripting

extract DDL - output every match to separate file

Hi, i want to extract the 'CREATE INDEX' or 'CREATE UNIQUE INDEX' statements from a ddl file and output each match to a separate file. i was looking around the net but couldnīt find anything. a possible sed-script could be: sed -n '/CREATE*INDEX*/,/COMMIT/p' filename.ddlbut i couldnīt find out... (11 Replies)
Discussion started by: CactusMoon
11 Replies

8. Shell Programming and Scripting

Extract all content that match exactly only specific word

Input: 21 templeta parent 35718 36554 . - . ID=parent_cluster_50.21.11; Name=Partial%20parent%20for%20training%20set; 21 templeta kids 35718 36554 . - . ID=_52; Parent=parent_cluster_5085.21.11; 21 templeta ... (7 Replies)
Discussion started by: patrick87
7 Replies

9. Shell Programming and Scripting

Extract data from records that match pattern

Hi Guys, I have a file as follows: a b c 1 2 3 4 pp gg gh hh 1 2 fm 3 4 g h i j k l m 1 2 3 4 d e f g h j i k l 1 2 3 f 3 4 r t y u i o p d p re 1 2 3 f 4 t y w e q w r a s p a 1 2 3 4 I am trying to extract all the 2's from each row. 2 is just an example... (6 Replies)
Discussion started by: npatwardhan
6 Replies

10. UNIX for Dummies Questions & Answers

Match and Extract

Hi, I am having 2 files which are as follows : File 1 1*001 2*002 3*003 4*004 File2 002 003 I want to match the entries in File 2 against File1.If an entry from File2 is found in File1 then I need to extract the number before "*" (a delimiter) for example...i pick up... (4 Replies)
Discussion started by: tushar_johri
4 Replies
Login or Register to Ask a Question