Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

need to enter dashs into a string of characters "123456789" using sed result s/b "123-45-6789"

Posted on 2004-04-15
3
309 Views
Last Modified: 2010-04-17
Have an ascii file that contains lines of data in the format:
 
12345~123456789~
12346~023456789~
 
Need to place dashes into send string of numbers to format a social security number
 
123-45-6789
023-45-6789
 
Would like to do this on the command line using sed, if possible. The data would be piped to the sed command.
0
Comment
Question by:kphillips1
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
fim32 earned 50 total points
ID: 10835789
you want to use sed to insert dashes, so that you get:

12345~123-45-6789~

upon completion?

sed -e 's/\(~...\)\(..\)/\1-\2-/;'

you just want:
123-45-6789
sed -e 's/.*~\(...\)\(..\)\(....\)~/\1-\2-\3/;'
0
 

Author Comment

by:kphillips1
ID: 10835846
Yes I would like the output to be:  "12345~123-45-6789"
 
The data is a listing of client ids and there order numbers
0
 
LVL 7

Expert Comment

by:fim32
ID: 10836332
so you want the output to remove the trailing ~?

then:
sed -e 's/\(~...\)\(..\)\(....\)~/\1-\2-\3/;'
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about a problem I had getting the GPS LocationListener working.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question