Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
On Tue, 2 May 2006, Rick wrote:
Would this work?
cat file | egrep "^1" | sed 's/x //'
That's the sort of thing I'm trying to avoid (see comments about egrep
below). But that also isn't right -- it removes every line that does not
begin with 1. This is more like it:
egrep "^1" file | sed 's/x/ /' > part1
egrep -v "^1" file > part2
cat part1 part2 | sort > outfile
This works because my file is sorted, but if the file was not sorted and
the order mattered, this also would fail (that's why I was talking about
"cat -n" below - I could add line numbers for sorting purposes).
Mike
Mike Miller wrote:
This must be something I can do in a one-liner: Suppose I have a file
where I want to remove all occurances of a certain character from lines
that match a pattern, like all 'x' characters from every line that begins
with '1':
3 7 x 5 x 9
1 x 2 2 z x
9 9 9 x 9 9
1 2 23 x 7
Maybe I want to replace every 'x' with a space only when the first
character in the line is a '1', otherwise I leave the x's alone. Any
ideas?
The way I would do it is lame: Remove the lines beginning with 1, process
them, then put them back. I would do egrep twice (once with -v), maybe
using cat -n to add line numbers, then take out the x's and put them back
together, sort, take out the line numbers. That is embarrassing though.
Mike
--
We simply can't idiot-proof everything. Sometimes the idiots just have to
suffer and die.
--http://www.overheardintheoffice.com/
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members