|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | 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 and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Delete until Nth occurence (sed, awk)
Hello people, Once more I need your help with SED/AWK I need to delete up to the Nth occurence of a char (from the beggining) and until the Mth occurence of a char (from the end) Example: Input: Code:
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z Output: Code:
i,j Must delete up to the 8th comma from the beggining and upo to the 16th comma from the end. For each line Thank you in advance for your help. Last edited by Scrutinizer; 01-09-2013 at 07:35 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Try: Code:
sed 's/\([^,]*,\)\{8\}//; s/\(,[^,]*\)\{16\}$//' fileLast edited by Scrutinizer; 01-09-2013 at 08:14 AM.. |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Code:
awk '{for(i=s+1;i<=NF-e;i++) printf("%s%c", $i,(i==NF-e)?ORS:OFS)}' s=8 e=16 FS=, OFS=, myFile |
| The Following User Says Thank You to vgersh99 For This Useful Post: | ||
drbiloukos (01-09-2013) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using tr, sed or awk to delete text from nth column only | hlwright | Shell Programming and Scripting | 6 | 09-02-2011 03:51 PM |
| To find the Nth Occurence of Search String | mac4rfree | UNIX for Dummies Questions & Answers | 3 | 07-27-2011 02:16 AM |
| Replacing nth occurence | raghav288 | Shell Programming and Scripting | 11 | 10-29-2009 11:39 AM |
| Replace matching nth occurence | raghav288 | Shell Programming and Scripting | 1 | 10-29-2009 10:19 AM |
| delete line upto the nth occurence of a particular charachter. | kashifv | Shell Programming and Scripting | 12 | 10-09-2009 06:26 AM |
|
|