1827293 Members
2852 Online
109717 Solutions
New Discussion

sed command

 
SOLVED
Go to solution
Anwar D Singh
Occasional Contributor

sed command

HI,

using the sed command, how can I:

a. remove the entries ending in 500

b. print the contents of the file with the last name and first names reversed.

Here is the file and you time and help is grealty appreciated.

Betty Boop:245-836-8357:635 Cutesy Lane, Hollywood, CA 91464:6/23/23:14500
Paco Gutierrez:835-365-1284:454 Easy Street, Decatur, IL 75732:2/28/53:123500
Sir Lancelot:837-835-8257:474 Camelot Boulevard, Bath, WY 28356:5/13/69:24500
Zippy Pinhead:834-823-8319:2356 Bizarro Ave., Farmount, IL 84357:1/1/67:89500.


6 REPLIES 6
Chris Wilshaw
Honored Contributor
Solution

Re: sed command

Removing the lines is easier with grep

grep -v "500$"

Should take care of that.
Robin Wakefield
Honored Contributor

Re: sed command

Hi Anwar,

a) sed '/500$/d' filename
b) sed 's/^\([^ ]*\) \([^:]*\)/\2 \1/' filename

Rgds, Robin
James R. Ferguson
Acclaimed Contributor

Re: sed command

Hi:

# sed -e '/500$/'d filename

# awk -F: '{split($1,a," ");$1=a[2]" "a[1];print $0}'

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: sed command

Hi (again):

OOps, forgot the input file!

awk -F: '{split($1,a," ");$1=a[2]" "a[1];print $0}' filename

Regards!

...JRF...
harry d brown jr
Honored Contributor

Re: sed command

Anwar,

Are there any middle initials in the names, suffixes, hypenated names, ... ??

live free or die
harry
Live Free or Die
Leif Halvarsson_2
Honored Contributor

Re: sed command

Hi
In general, awk is a better tool for formatted files (and sed is better for plain text).

example:

BEGIN { FS = ":" }
function abc(a)
{
n=match(a," ")
return n
}

{ print substr($1,abc($1)+1)" "substr($1,0,abc($1))" "$2 $3 $4 }

call this file test.awk and run
awk -f test.awk

I don't understand "entries ending with 500", all lines ends with 500.