tags:

views:

56

answers:

2

I have a file with a string on each line... ie.

test.434
test.4343
test.4343t34
test^tests.344
test^34534/test

I want to find any line containing a "^" and replace entire line with a blank.

I was trying to use sed:

sed -e '/\^/s/*//g' test.file

This does not seem to work, any suggestions?

+4  A: 
sed -e 's/^.*\^.*$//' test.file

For example:

$ cat test.file
test.434
test.4343
test.4343t34
test^tests.344
test^34534/test
$ sed -e 's/^.*\^.*$//' test.file
test.434
test.4343
test.4343t34


$

To delete the offending lines entirely, use

$ sed -e '/\^/d' test.file
test.434
test.4343
test.4343t34
Greg Bacon
Thanks that does work, is there a way to get that to remove the line entirely? Instead of just replacing it with a blank line?
Chris
@Chris See update.
Greg Bacon
Right but, is there a way to do it in one line? More curiosity sake than to negate your solution... :-)_
Chris
That *is* one line, no?
You
@Chris The second `sed` command operates on the original `test.file` from your question and does its work in a single step.
Greg Bacon
A: 

other ways

awk

awk '!/\^/' file

bash

while read -r line
do
  case "$line" in
    *"^"* ) continue;;
    *) echo "$line"
  esac
done <"file"

and probably the fastest

grep -v "\^" file
ghostdog74