Remove Extra Delimiter


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove Extra Delimiter
# 1  
Old 04-19-2013
Remove Extra Delimiter

Hi ,

I have file like this..

Code:
 
aaa|bbbb|cccc|dddd|fff|dsaaFFDFD|
Adsads|sas|sa|as|asa|saddas|dsasd|sdad|
dsas|dss|sss|sss|ddd|dssd|rrr|fddf|
www|fff|refd|dads|fsdf|00sd|
5fgdg|dfs00|d55f|sfds55|445fsd|55ds|sdf|

so I do no have any fix pattern and I want to remove extra delimiter(|) and want to keep six delimiter(|) in each row.
I've done googling and try to use sed command , but have not able to do it.
# 2  
Old 04-19-2013
Yes, you made the right choice to try sed:
Code:
$ sed "s/|$//" file
aaa|bbbb|cccc|dddd|fff|dsaaFFDFD
Adsads|sas|sa|as|asa|saddas|dsasd|sdad
dsas|dss|sss|sss|ddd|dssd|rrr|fddf
www|fff|refd|dads|fsdf|00sd
5fgdg|dfs00|d55f|sfds55|445fsd|55ds|sdf

This User Gave Thanks to hanson44 For This Post:
# 3  
Old 04-19-2013
Hi,

I am using sed like this

Code:
sed "s/|$//" File

but I want to keep only 6 delimiter(|) in each row and this command does not work for that
# 4  
Old 04-19-2013
Do you want delete 6th delimiter not last delimeter right ??
# 5  
Old 04-19-2013
Quote:
I want to keep only 6 delimiter(|) in each row
I apologize. I didn't see that your input file has all those varying numbers of delimiters.

If you only want six remaining, it is not clear what to do with some of the lines, whether to retain the data or not. Here is the input:
Code:
aaa|bbbb|cccc|dddd|fff|dsaaFFDFD|
Adsads|sas|sa|as|asa|saddas|dsasd|sdad|
dsas|dss|sss|sss|ddd|dssd|rrr|fddf|
www|fff|refd|dads|fsdf|00sd|
5fgdg|dfs00|d55f|sfds55|445fsd|55ds|sdf|

Is this the output you want, or something different:
Code:
aaa|bbbb|cccc|dddd|fff|dsaaFFDFD|
Adsads|sas|sa|as|asa|saddas|
dsas|dss|sss|sss|ddd|dssd|
www|fff|refd|dads|fsdf|00sd|
5fgdg|dfs00|d55f|sfds55|445fsd|55ds|

# 6  
Old 04-19-2013
Hi,

I want data like this.

Code:
aaa      |bbbb |cccc |dddd  |fff      |dsaaFFDFD|       
Adsads |sas   |saas  |asa   |saddas |dsasdsdad|       
dsas    |dss   |ssssss|ddd   |dssdrrr | fddf    |       
www    |fff    |refd   |dads  |fsdf     |00sd     |       
5fgdg   |dfs00|d55f  |sfds55|445fsd  |55dssdf |

each row contain only 6 delimiter(|) means there are only 6 column in this file
# 7  
Old 04-19-2013
Well, for example the third row:
Code:
dsas|dss|sss|sss|ddd|dssd|rrr|fddf|

You indicate you want to change it to:
Code:
dsas|dss|ssssss|ddd|dssdrrr|fddf|

Here's what happened:
Code:
dsas -> dsas
dss -> dss
sss and sss -> ssssss
ddd -> ddd
dssd and rrr -> dssdrrr
fddf -> fddf

What's the logic to decide which columns to combine? For example, why are dssd and rrr combined, instead of rrr and fddf?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

File Containing Extra delimiter should be removed

The input file is this: a|b|c|d x|y|z|n||||||||| p|q|r|s||| g|h|i| w|e|r|| Now as per requirement , each row should have only 3 delimiter. Now the 2nd row & last row has an extra delimiter, How to remove that ? In some large file having 100K data , there can be 100 such rows having... (4 Replies)
Discussion started by: ikdKunal
4 Replies

2. Shell Programming and Scripting

Extra Space in output - remove

Hi All I am trying to perform the below operation -count=`cat abc.txt | wc -l` echo$count 5 Head=Start"$DATE"00000"$count"File echo $HEAD START15020300000 5File There is a space coming before 5 which is not needed . How to ignore that . (4 Replies)
Discussion started by: honey26
4 Replies

3. Shell Programming and Scripting

Remove of extra spaces from the trailing

HI, I need the help from the experts like I have created one file with text like: a b c d e f g h i j k l So my question is that i have to write the script in which like in the first sentence it will take only one space after d and remove all the extra space in the end.I dont... (8 Replies)
Discussion started by: bhanudhingra
8 Replies

4. UNIX for Dummies Questions & Answers

how to remove extra characters

Guys, I have a file that contains entries like this: LaxOrdID=19220288<8> LaxOrdID=19220288 I would like to remove <> and the values inside it anywhere its found. How? (2 Replies)
Discussion started by: DallasT
2 Replies

5. Shell Programming and Scripting

Remove extra character

Hi I am using cat <filename> command in one of my datastage job(Command Activity). It is giving actual value but giving extra line. Eg: Displayed Output: 1 and showing extraline(Eg: 1 ) I had checked even wc -c it is giving one character extra. If the file contains 11. wc -c says 3. ... (3 Replies)
Discussion started by: cnrj
3 Replies

6. Shell Programming and Scripting

How to remove extra spaces from a string??

Hi, I have a string like this and i want to remove extra spaces that exists between the words. Here is the sentence. $string="The small DNA genome of hepadnaviruses is replicated by reverse transcription via an RNA intermediate. This RNA "pregenome" contains ... (2 Replies)
Discussion started by: vanitham
2 Replies

7. Shell Programming and Scripting

remove extra spaces between fields

Hi, I have a source file as mentioned below: I want to remove all the extra spaces between the fields. a b--------|sa df-------|3232---|3 sf sa------|afs sdf-----|43-----|33 a b c------|adfsa dsf---|23-32|23 *Here '-' idicates spaces Now, I want output as below: a b|sa df|3232|3... (7 Replies)
Discussion started by: srilaxmi
7 Replies

8. Shell Programming and Scripting

Remove extra spaces in a line

Hi, I need a help in deleting extra spaces in a text. I have a huge file, a part of it is :- 3 09/21/08 03:32:07 started undef mino Oracle nmx004.wwdc.numonyx.com Message Text : The Oracle session with the PID 1103 has a CPU time ... (6 Replies)
Discussion started by: vikas027
6 Replies

9. UNIX for Dummies Questions & Answers

To remove the extra spaces in unix

Hi... I am quite new to Unix and would like an issue to be resolved. I have a file in the format below; 4,Reclaim,ECXTEST02,abc123,Harry Potter,5432 6730 0327 5469,0603,,MC,,1200,EUR,sho-001,,1,,,abc123,1223 I would like my output to be as follows; 4,Reclaim,ECXTEST02,abc123,Harry... (4 Replies)
Discussion started by: Sho
4 Replies

10. Shell Programming and Scripting

remove extra lines in the file

Hi, I have some files, with some extra lines in weird characters on the top and bottom of the. I want to get rid of those line. Is there a way I can do that? example of the input file. I want to get rid of those lines in bold  ... (8 Replies)
Discussion started by: CamTu
8 Replies
Login or Register to Ask a Question