LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Stuck with a single sed script (https://www.linuxquestions.org/questions/linux-newbie-8/stuck-with-a-single-sed-script-4175430591/)

r_clark2 10-04-2012 09:04 PM

Stuck with a single sed script
 
I have to write a single sed script that will remove items in a text file that was assigned to work with. The issue that I have is I have to delete just the part of the line that ends with 500 Please help!
Here is what the text looks like:
Hollywood, CA 91464:6/23/23:14500
Decatur, IL 75732:2/28/53:123500
Gary, IN 83756:12/1/46:268500
Milton, PA 93756:9/21/46:43500
Bath, WY 28356:5/13/69:24500
Farmount, IL 84357:1/1/67:89500


And again I have to write a single sed script and cat the script in the text to make the changes and I have an even bigger challenge after this. I have to change the names to be last, first name and the currently are listed as first, last name.
I have attempted several scripts already and I have yet to get it to work, such as /...500$// /...500$d/

cbtshare 10-04-2012 11:29 PM

show us what you have already and we can assist further...this seems like home work, as per forum rules , we cant do home work for you.

druuna 10-05-2012 01:27 AM

Quote:

Originally Posted by r_clark2 (Post 4797668)
I have to write a single sed script that will remove items in a text file that was assigned to work with. The issue that I have is I have to delete just the salaries in a line that end with 500, the salaries are at the end of the lines and again I just need to delete the salaries that end in 500. Please help!
.
.
I have attempted several scripts already and I have yet to get it to work, such as /...500$// /...500$d/

I agree that this looks like homework, but you do mention some sort of a solution at the end.

With sed you can search for a certain pattern and perform an action if that pattern is found. The solution you played with (/...500$d/) is close but syntactically incorrect.

You first tell sed what you are looking for, 500 at the end of a line: /500$/. Then you tell sed what you want to do, in this case you want to delete the line, which is done by the d option. Putting both together will give you this: /500$/d

Here's a link to a good sed tutorial: Sed - An Introduction and Tutorial

This explains the delete option: Sed - Delete with d

pan64 10-05-2012 03:49 AM

duplicate of http://www.linuxquestions.org/questi...=1#post4797866

r_clark2 10-05-2012 10:06 AM

Thank you everyone for your assistance, it is actually a project that I am working on I work in academia and I am new to Unix scripting/programming.


All times are GMT -5. The time now is 10:27 AM.