![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
Code:
#!/bin/ksh REMOVE=$1 cat test.in | tr '\|' '\n' | grep -v ^$ | grep -v "$REMOVE" | tr '\n' '\|' echo exit 0 |
|||
| Google The UNIX and Linux Forums |