![]() |
|
|
|
|
|||||||
| 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 |
| Help removing lines with duplicated columns | yahyaaa | Shell Programming and Scripting | 14 | 05-17-2008 04:33 AM |
| remove duplicated columns | kamel.seg | Shell Programming and Scripting | 6 | 02-21-2008 04:36 AM |
| Can root ID be duplicated | lorcan | UNIX for Advanced & Expert Users | 6 | 06-15-2007 08:06 PM |
| grep and delete 2nd duplicated of txt... -part2 | happyv | Shell Programming and Scripting | 16 | 01-19-2007 02:40 AM |
| Log files duplicated themselves? | DISTURBED | UNIX for Dummies Questions & Answers | 4 | 07-01-2002 06:54 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
using sed to get rid of duplicated columns...
I can not figure out this one, so I turn to unix.com for help, I have a file, in which there are some lines containing continuously duplicate columns, like the following
adb abc abc asd adfj 123 123 123 345 234 444 444 444 444 444 23 and the output I want is adb abc asd adfj 123 345 234 444 23 Is it possible using sed to do this? oh, btw, I thought this should work, sed 's/(\([^ ]\)+ )+/\1/' file , but it does not... Last edited by fedora; 04-10-2008 at 12:53 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
You need to have backrefs already in the first part to make sure you are actually replacing repeats, otherwise it will simply reduce every line to one token (or two, if you require a trailing space after the replacement). Also you need to make up your mind on whether your sed requires a backslash before grouping parentheses or not.
Code:
sed 's/\([^ ]* \)\1*/\1/g' file |
|
#3
|
|||
|
|||
|
Quote:
|
|
#4
|
|||
|
|||
|
hmm, a second though, it seems that something is still wrong
>cat /tmp/test 123 123 123 345 akljsdfaljskd 7878 7878 7878 7878 123 akljsdfaljskd 7878 7878 7878 7878 123 123 123 345 234 345 345 >sed 's/\([^ ]* \)\1*/\1/g' /tmp/test 123 345 akljsdfaljskd 7878 123 akljsdfaljskd 7878 123 345 234 345 345 note the last line, the duplicate "345" are still there |
|
#5
|
|||
|
|||
|
hmm, that last column does not have "space", which is why...
|
|
#6
|
|||
|
|||
|
Can you explain the syntax you have given in details
sed 's/\([^ ]* \)\1*/\1/g' file Thanx |
|||
| Google The UNIX and Linux Forums |