Replacement of Delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacement of Delimiter
# 1  
Old 05-14-2007
Question Replacement of Delimiter

Dear all,
i have a proble.
in my input file i have records with delimiter like

aa-------bb------cc--vghjav---ef----kjd
dj--------ih------yy--ujdjkkl---dd----jid

now i want to replace the delimiter "-" with "~"
i have used a command i.e
cat FILENAME | tr "-" "~" >> Newfile

this command replacing the input delimiter one by one like

aa~~~~~~~bb~~~~~~cc~~vghjav~~~ef~~~~kjd
dj~~~~~~~ih~~~~~~yy~~ujdjkkl~~~dd~~~~jid

but the output i want is

aa~bb~cc~vghjav~ef~kjd
dj~ih~yy~ujdjkkl~dd~jid

like this

can any one please help me out regarding this problem?

Regards,
Pankaj
# 2  
Old 05-14-2007
Code:
sed 's/--*/~/g' FILENAME > NewFile

Jean-Pierre.
# 3  
Old 05-14-2007
Code:
awk '{gsub("-+","~");print}' file    > newfile

# 4  
Old 05-14-2007
Hi.
Code:
       -s, --squeeze-repeats
              replace each input sequence of  a  repeated  character  that  is
              listed in SET1 with a single occurrence of that character

-- excerpt from man tr

cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Is this MB, which needs replacement ?

Hello, I am getting below error in fmadm output. This server is not in support, so can't reach them. Is it showing that motherboard is faulty and should be replaced ? It was rebooted a week back and then, there were no errors # fmadm faulty --------------- ------------------------------------ ... (1 Reply)
Discussion started by: solaris_1977
1 Replies

2. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

3. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

4. Shell Programming and Scripting

selective replacement of delimiter

I have a file with two fields seperated by comma data looks like below with the header The o/p should look like this Basically, the req is to replace only the first occuring comma with pipe can we do this with any commands (2 Replies)
Discussion started by: dsravan
2 Replies

5. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

6. UNIX for Dummies Questions & Answers

replacement

my filename.txt looks like this: 2079951061790 SCK0000891539000000000000021600R 2079951061790 SCK0000901487000000000000028900R 2079951061790 SCK0000903092000000000000021300R 2079951074758 ... (9 Replies)
Discussion started by: tjmannonline
9 Replies

7. Shell Programming and Scripting

help me :replacement

Hi pls help me for below; i have a file .content is : =================== uid,pcsPricingPlan,refPcsQosProfName 821910002022,smartlimit,SGSNQOS1 i have to replace the value of uid and pricingplan by a unix script. may be the value would be next line or any where in the file. pls... (9 Replies)
Discussion started by: Aditya.Gurgaon
9 Replies

8. Shell Programming and Scripting

Conditional replacement of a delimiter

Hello, I'm new to this forum but this seems like the place to ask this question. I have a pipe delimited data file with the fields except for the header being encased in double quotes. I found out that some of the fields have an trash pipe within the data itself. I'd like to conditionally... (4 Replies)
Discussion started by: samahs
4 Replies

9. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

10. UNIX for Dummies Questions & Answers

Regarding Replacement

I have two files: file1: somedata <html> <head> This is sample statement ...... ...... </head> </html> somedata file2: olga 81 91 B A rene 82 92 B A zack 83 93 Expextd Result: (2 Replies)
Discussion started by: rajx
2 Replies
Login or Register to Ask a Question