[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
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
Medium Priority
?
345 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
[X]
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
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
fim32 earned 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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.
In this post we will learn different types of Android Layout and some basics of an Android App.
Simple Linear Regression
Starting up a Project

649 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