• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

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

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
kphillips1
Asked:
kphillips1
  • 2
1 Solution
 
fim32Commented:
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
 
kphillips1Author Commented:
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
 
fim32Commented:
so you want the output to remove the trailing ~?

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now