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
320 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Arduino EDI - Programming Language - Voice Recorder 4 105
simplest php form 3 85
ejb entity bean example 2 37
statistics basics sources 2 41
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

733 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