|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | 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
|
|||
|
|||
|
Replace a string after n semicolon every line
I have a file that is formatted in this way. Code:
a1;b2;c33;d4;e5;e;f;f;f;s d;ds;d;a;v;b;g;gr;r;rt;fdf s1;s2;s2;s3;s4; b1;f2;g3;h4;a3c4e;xcsd;fds; sd2;fs4;fs2;sdf3; I want to replace the value just before the 4th semicolon to empty string, regardless the value, such that it looks like this for every block of data separated by a line Code:
a1;b2;c33;;e5;e;f;f;f;s d;ds;d;a;v;b;g;gr;r;rt;fdf s1;s2;s2;s3;s4; b1;f2;g3;;a3c4e;xcsd;fds; sd2;fs4;fs2;sdf3; I tried using Code:
sed 's/[^*];//4' but to no avail. Any ideas? Last edited by alienated; 07-29-2010 at 11:23 AM.. |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Code:
echo 'a1;b2;c33;d4;e5' | nawk -F';' '{$4=""}1' OFS=';'
OR
echo 'a1;b2;c33;d4;e5' | sed 's/[^;][^;]*;/;/4'Last edited by vgersh99; 07-29-2010 at 11:38 AM.. Reason: regex fix |
| The Following User Says Thank You to vgersh99 For This Useful Post: | ||
alienated (07-29-2010) | ||
| Sponsored Links | ||
|
|
|
#4
|
|||
|
|||
|
Code:
# echo 'a1;b2;c33;d4;e5' | sed 's/[^;]*;/;/4' a1;b2;c33;;e5 Code:
# echo 'a1;b2;c33;d4;e5' | sed 's/\(.*\)[a-z][0-9]*;\([a-z0-9]*\)*$/\1;\2/' a1;b2;c33;;e5 |
| Sponsored Links | ||
|
|
![]() |
| Tags |
| nawk |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Replace blank spaces with semicolon - text file | mpcengineering | Shell Programming and Scripting | 3 | 11-30-2009 07:36 AM |
| How to replace a particular string in a line | Raju Datla | Red Hat | 1 | 01-09-2009 04:02 AM |
| search for a string ,replace the whole line with new line | kkraja | Shell Programming and Scripting | 4 | 08-07-2008 02:26 AM |
| sed conditional string replace for each line | Nanu_Manju | Shell Programming and Scripting | 6 | 04-14-2008 02:16 PM |
| put a semicolon at the end of each line of a file | surjyap | Shell Programming and Scripting | 1 | 02-13-2006 10:05 AM |
|
|