Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PATTERN MATCH , NOT IN LIST COMMAND

Status
Not open for further replies.

sachrath

Programmer
May 21, 2004
17
CH
Hi All,

I have a file with name F and 10 fields and 100 records .
I need to create a new file name F.child out of this base file F , such that only those records come into the F.child file for which column_2 of file F not in ('AUES','ALDJ').

I am not able to acheive " NOT IN LIST " operation for the above situation .

Any help is appreciated .

Thx
Sachin Rath.
 
Something like this ?
awk '$2!="AUES" && $2!="ALDJ"' F >F.child

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Vo fast PHV .

Well!

CURRENT PROBLEM
*****************

The base file name is F , with 10 attributes and 100 records and delimiter as '|' .
I need to split this file into 2 files , on the basis of 3 column values (c_1,c_2,c_3).

File 1--> Name F.child1 , if column
c_1='CSFPRODLONGB' , c_2='IRS' and c_3='C' for which the search expression I passed as '^CSFPRODLONGB\|IRS\|C' and it worked successfully creating F.child1 .

File 1--> Name F.child2 , if column
c_1='CSFPRODLONGB' , c_2 NOT IN ('TRS','ETRS') and c_3='C' for which the search expression I passed as
'^CSFPRODLONGB\|(!=TRS && !=ETRS)\|C' as u had suggested , doesnt bring anything and hence creating a file F.child2 , but with no recds , although the base file has records satisfying the above conditions as well.
Is that expression incorrect ?

Cheers
Sachin
 
Something like this ?
awk -F'|' '
$1!="CSFPRODLONGB" || $3=="c"{next}
$2=="IRS"{print >"F.child1";next}
$2!="TRS" && $2!="ETRS"{print >"F.child2"}
' F

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Sorry for the typo:
awk -F'|' '
$1!="CSFPRODLONGB" || $3[highlight]!="C"[/highlight]{next}
$2=="IRS"{print >"F.child1";next}
$2!="TRS" && $2!="ETRS"{print >"F.child2"}
' F

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Didnt work either :(

I tried in this way "'^CSFPRODLONGB\|IRS\|!=(TRS|ETRS)\|C'".

Sachin
 
Can you please post an example of input file (F) ?
Have you tried to copy-paste the lines of code I posted ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Perhaps use case for pattern match...

while read line
do
case $line in
CSFPRODLONGB\|TRS\|C*) print -u4 $line ;;
CSFPRODLONGB\|ETRS\|C*) print -u4 $line ;;
CSFPRODLONGB\|*\|C*) print -u3 $line ;;
esac
done < F 3> F.child1 4> F.child2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top