1

How can I remove price from following data in Shell Script? I am printing labels and don't want to show price.

Input:

Order: 12
Name: Raj K
ABC Inc
123 Main St
Edison NJ

1 Printer - $50.09
Router - $30.00
2 AirPrint - $56.10

Output

Order: 12
Name: Raj K
ABC Inc
123 Main St
Edison NJ

1 Printer
Router
2 AirPrint

Any ideas?

4
  • 1
    What tools do you have (sed/awk/perl/bash/...), are the prices always exactly like that, and what have you tried so far? Commented May 14, 2012 at 18:34
  • I was using few pattern match in sed but no luck. The shell is bash. I think, I can use perl in the shell script as well, if there is an easy way to do it. Commented May 14, 2012 at 18:37
  • Please include the things you tried in your question. This will allow people to tell you where you got it wrong and/or how you can do it better. You'll learn more that way. Commented May 14, 2012 at 18:38
  • The solution below given by Tim works with sed. I was using wrong pattern matches. Thank you. Commented May 14, 2012 at 18:39

1 Answer 1

1

Use sed:

sed '/ *- *\$[0-9]\+\.[0-9]\{2\}/s///' file

This has been updated in response to Glenn's comment below.

Sign up to request clarification or add additional context in comments.

2 Comments

You could also take advantage of sed's use of an empty regex re-using the previous one: sed '/ \+- \+\$[[:digit:]]\+\.[[:digit:]]\{2\}/s///'
@glennjackman B.A. I had no idea that existed. Edited per your recommendation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.