The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
cut awk dummy question :) sopel39 UNIX for Dummies Questions & Answers 14 11-14-2007 11:14 AM
using grep for a dummy mkosucu UNIX for Dummies Questions & Answers 3 10-28-2007 12:56 AM
Curious Dummy highway39 UNIX for Dummies Questions & Answers 1 08-31-2006 04:22 PM
Dummy Needs Help amygdala UNIX for Dummies Questions & Answers 4 08-31-2001 08:14 PM
Real Dummy here!! Keith UNIX for Dummies Questions & Answers 2 02-06-2001 11:18 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 03-10-2006
Registered User
 

Join Date: Feb 2006
Posts: 66
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
Reply With Quote
Forum Sponsor
  #9  
Old 03-11-2006
Registered User
 

Join Date: Feb 2006
Posts: 10
Code:
#!/bin/ksh

REMOVE=$1

cat test.in | tr '\|' '\n' | grep -v ^$ | grep -v "$REMOVE" | tr '\n' '\|'
echo

exit 0
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0