Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I remove the first half of each line in a file? 2

Status
Not open for further replies.

cpjust

Programmer
Sep 23, 2003
2,132
US
Hi,
I have a file like this:
Code:
blah blah blah myschema.table1 blah
blah blah myschema.table2 blah blah
...
and what I want to do is remove everything before the "myschema." on each line so that it becomes:
Code:
myschema.table1 blah
myschema.table2 blah blah
how would I do that?

I tried using sed like this, but it says "unknown command: `f'"
Code:
echo /Chris/myschema-find.txt | sed '/^.*myschema\..*$/myschema\..*$/'
Somebody said awk might be what I'm looking for, but I have no idea how to use awk and can barely use sed. :p
 
[tt]sed 's/^.*myschema/myschema/'[/tt]


HTH,

p5wizard
 
Thanks.
Obviously the echo part didn't work either, but I got it working by passing the filename as the 2nd parameter to sed.
 
Now what if I want to remove everything after the first space?
So change this:
Code:
myschema.table1 blah blah
myschema.table2 blah
to:
Code:
myschema.table1
myschema.table2
 
Nevermind, I got it:
Code:
sed "s/ .*$//" /Chris/myschema-find1.txt > myschema-find2.txt
 
You don't need a temporary file:
Code:
sed 's/^.*myschema/myschema/;s/ .*$//' /Chris/myschema-find.txt > /Chris/myschema-find1.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top