If not ...then


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If not ...then
# 1  
Old 02-13-2006
If not ...then

Hi all,

Hi have a flat file and at 19 fields , separate by a comma ,
here are colummn field 19

FE-Router:MN-Menu:SV-SvcMenu:SV-SvcStop:AC-Lkup:AC-StNumQry:AC-Elig:SV-GetZipCode:SV-GetAddress:SV-GetSecondary:SV-ConfStreetAddress:FE-XferCSR

or

FE-Router:MN-Menu:BP-FinStatus:AC-Lkup:AC-PhNumLkup:AC-AcNumLkup:AC-StNumQry:AC-Elig:BP-FinStatus2:BP-OtherPymt:FE-XferCSR

or

FE-Router:OR-Menu1

===============
How do I collect the list that does not start with 'FE' or 'MN' (entries are separated by a colon) .
If you look at then the answer is location=SV-SvcMenu

If you look at then the answer is location=BP-FinStatus

If you look at then the answer is location=OR-Menu1

This drive me crazy , can you show me how to solve it in ksh? I will use location to send out put to another new flat file
example:

Date|name|Location|Doc|...
Thanks,

Last edited by sabercats; 02-13-2006 at 07:28 PM..
# 2  
Old 02-13-2006
Yucky but...
Code:
nawk -F: '
{ str=""
  for (i=1; i <= NF; i++) if ($i !~ /^FE|^MN/) str=str ":" $i 
  sub(/^:/,"",str)
  printf str "\n"
}' < yourfile

output:
Code:
SV-SvcMenu:SV-SvcStop:AC-Lkup:AC-StNumQry:AC-Elig:SV-GetZipCode:SV-GetAddress:SV-GetSecondary:SV-ConfStreetAddress
BP-FinStatus:AC-Lkup:AC-PhNumLkup:AC-AcNumLkup:AC-StNumQry:AC-Elig:BP-FinStatus2:BP-OtherPymt
OR-Menu1

# 3  
Old 02-13-2006
wow, thanks alot , but if I only need

SV-SvcMenu
BP-FinStatus
OR-Menu1

then how do I get it ?
# 4  
Old 02-13-2006
This is GNU sed ...
Code:
$ cat file1
FE-Router:MN-Menu:SV-SvcMenu:SV-SvcStop:AC-Lkup:AC-StNumQry:AC-Elig:SV-GetZipCode:SV-GetAddress:SV-GetSecondary:SV-ConfStreetAddress:FE-XferCSR
FE-Router:MN-Menu:BP-FinStatus:AC-Lkup:AC-PhNumLkup:AC-AcNumLkup:AC-StNumQry:AC-Elig:BP-FinStatus2:BP-OtherPymt:FE-XferCSR
FE-Router:OR-Menu1

$ sed -r -e 's/(FE|MN)-[^:]*/:/g'  -e 's/:*([^:]*).*/\1/' file1
SV-SvcMenu
BP-FinStatus
OR-Menu1

# 5  
Old 02-14-2006
I can not use sed in this case because sed look for a file, but I look for a field.

here is my code:
========

#!/bin/ksh
cd /DATA
for file in MainCD*log; do
newFile=`ls -1 $file|awk -F. '{ \
y = substr($1,7,4); \
m = substr($1,11,2); \
d = substr($1,13,2); \
printf "irv-%s%s%s.dat",y,m,d \
}'`
grep "," $file |
sort -t"|" +1 -2 +5 -6 |
awk -F"," '{

if (($5 == "002") && ($6 == "FE")) {
ani = $7;
logdate = $3;
logtime = $4;

lastloc = $10;
acc = $9;

if ($19 !~ /^FE|^MN/)

sub(/^:/,"",firstloc)

printf "%s|%s|%s|%s|%s|%s\n",ani,logdate,logtime,firstloc,lastloc,acc;

}

}' |
sort -t, +0 -1 > /NEWDIRECT/$newFile


done

============

I really want the firstloc have only
firstloc=SV-SvcMenu

or

firstloc= BP-FinStatus

Please show me what trick you will use Smilie
Thanks,
# 6  
Old 02-14-2006
Oh, I solve the problem, here is my code:

.......
list=$19;

sizeof_listarray=split(list,listarray,":")
firstloc="";

for (i=1; i <= sizeof_listarray; i++){
functarea=substr(listarray[i],1,2);
firstloc = listarray[i];
if (functarea != "FE" && functarea != "MN") {
break;
}
}
.....

Thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question