LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-04-2012, 10:04 PM   #1
r_clark2
LQ Newbie
 
Registered: Oct 2012
Location: MD
Distribution: Unix 12.04 LTS
Posts: 3

Rep: Reputation: Disabled
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/

Last edited by r_clark2; 10-05-2012 at 11:29 AM. Reason: add information
 
Old 10-05-2012, 12:29 AM   #2
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Rep: Reputation: 42
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.
 
Old 10-05-2012, 02:27 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by r_clark2 View Post
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
 
1 members found this post helpful.
Old 10-05-2012, 04:49 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
duplicate of http://www.linuxquestions.org/questi...=1#post4797866
 
1 members found this post helpful.
Old 10-05-2012, 11:06 AM   #5
r_clark2
LQ Newbie
 
Registered: Oct 2012
Location: MD
Distribution: Unix 12.04 LTS
Posts: 3

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Using sed to substitute repetition -> single occurrence rm_-rf_windows Linux - General 9 03-18-2012 11:12 AM
[SOLVED] How to merge this awk and sed codes in a single one? cgcamal Programming 10 03-14-2011 01:59 AM
insert zero before single numbers using sed (or awk) chess Programming 10 10-22-2008 09:06 AM
I am learning sed / grep working and am stuck with a problem chris_looks Linux - Newbie 12 08-14-2007 12:13 PM
I am learning sed / grep working and am stuck with a problem chris_looks Linux User Groups (LUG) 2 08-06-2007 02:31 PM


All times are GMT -5. The time now is 06:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration