HUm... this is not working as I wish
But I wrote this code like this can you show me the right way ??
If a file like test.in
Case Modify 10001 20002 30003 40004|Report Create 3417176211|Case Modify 10002 20002 30003 40005|CDxAcct=8201062400|CDxAcct=7294483553|
#!/bin/ksh
#remove.ksh
REMOVE=$1
cat test.in |
awk -F"\n" -v remove=$1 '{
input=$1;
remove_start=index(input,remove);
if (remove_start == 0) {
output = input;
} else {
if (remove_start == 1) {
output = substr(input,index(input,"|")+1);
} else {
output1 = substr(input,1,remove_start - 1);
output2 = substr(input,remove_start);
output = output1 substr(output2,index(output2,"|")+1);
}
}
printf "%s\n",output;
}'
Then if I run script
[b]
$remove.ksh "Case"
Report Create 3417176211|Case Modify 10002 20002 30003 40005|CDxAcct=8201062400|CDxAcct=7294483553|
It remove the first field ... it should not remove anything..
If I type
$remove.ksh "Case Modify 10002" then the answer should be
Case Modify 10001 20002 30003 40004|Report Create 3417176211|CDxAcct=8201062400|CDxAcct=7294483553|
and if do
$remove.ksh "Case Modify 10001" then the answer should be
Report Create 3417176211|Case Modify 10002 20002 30003 40005|CDxAcct=8201062400|CDxAcct=7294483553|
Please show me what I should do
. Thanks