|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Occurrence of two strings in a line of a file
Hi all, is there a way to find the occurrence of two strings in a line of a file? e.g. I have Code:
XXXX yyyyy zzzz 111
XXXX yyyyy zzzz 222
XXXX yyyyy zzzz 333
XXXX yyyyy zzzz 444and want to find in one shot Code:
XXXX yyyyy zzzz 222 Thank you, Sarah Last edited by Yogesh Sawant; 02-26-2010 at 12:25 PM.. Reason: added code tags |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Try: Code:
awk '/XXXX/ && /222/' < filename |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
can this be made case insensitive (on both strings)? maybe with grep?
|
|
#4
|
||||
|
||||
|
Quote:
Try: Code:
awk 'toupper($0) ~ /XXXX/ && /222/' < file |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
...mmhhh not working... it seems I get no match
could I have, instead of XXXX and 222, two variable in array? I tried something like OCCURRENCE=`awk '/blah/ && /${STRING_NAME[1]}/' tmp.tmp1| wc -l` but it does not work (it does if explicitly use the STRING_NAME value) Thank you, Last edited by f_o_555; 11-23-2009 at 10:15 AM.. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Code:
grep -Ei ^X{4}.*2{3}$ your_file |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
How can I put in two arbitrary strings $STRING1 and $STRING2?
grep -Ei $STRING1.$STRING2 doesn't work |
| Sponsored Links | ||
|
|
![]() |
| Tags |
| awk, grep |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Line number of an occurrence using grep | f_o_555 | UNIX for Dummies Questions & Answers | 5 | 11-24-2009 05:37 AM |
| Concatenate strings line by line | hagdanan | Shell Programming and Scripting | 6 | 12-12-2008 03:42 AM |
| Insert two strings at the beginning and at the end of each line of a file | Linux-fueled | Shell Programming and Scripting | 3 | 10-14-2008 12:26 PM |
| Third line occurrence replacement | sirokket16 | Shell Programming and Scripting | 5 | 07-03-2008 12:04 PM |
| Finding nth occurrence in line and replacing it | stresing | UNIX for Dummies Questions & Answers | 5 | 02-01-2008 03:56 AM |
|
|