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
277 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
fix34  challenge 9 98
Problem to setup 18 80
Batch file output 20 78
Eclipse Neon start with Admin account only 6 52
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now