help with awk or sed

Please clear your requirements: Should or should not add the line ppp.abcd.com if record exists in file?

yes i mean it will not it, if it is already exist.

one more thing pls, how to remove duplicate lines from file, if more than occurance.

kindly advice.

Thanks,
Bash

If you are attempting to maintain a hosts file or some such, perhaps it would be easier if you had a template and only add to the template, overwriting whatever was there before. (Perhaps this is not doable in your scenario, but if you can do it, it could simplify things a great deal.)

perl -i~ -nle ' BEGIN { %seen = ('tito-k.abcd.com' => 1, 'reta-k.abcd.com' => 1); }
print unless $seen{$_}++;
END { print "pppp.abcd.com" unless $seen{"pppp.abcd.com"}' file
perl -i~ -nle ' BEGIN { %seen = ('tito-k.abcd.com' => 1, 'reta-k.abcd.com' => 1); }
print unless $seen{$_}++;
END { print "pppp.abcd.com" unless $seen{"pppp.abcd.com"}' file

[/quote]

Hi,

Its giving error.

String found where operator expected at code line 1, near "nle ' BEGIN { %seen = ('"
(Do you need to predeclare nle?)
Bareword found where operator expected at code line 1, near "' BEGIN { %seen =

pls suggest.

Thanks,
Bash

Are you sure you copied era's code correctly? It sounds like you have somehow ended up with 'nle' inside the script part, instead of as a command-line option, which is what it should be.

Hi Greetings,

I use Era code as he describe, but i am sure a little thing might be missing.

pls advice Era.

Thanks,
Bash

Try this:

perl  -nle '
    BEGIN { %seen = ("tito-k.abcd.com" => 1, "reta-k.abcd.com" => 1); }
    print unless $seen{$_}++;
    END { print "pppp.abcd.com" unless $seen{"pppp.abcd.com"} }
' file

Yes, sorry for mixing in single quotes; dunno why I would have done that.

The error message indicates you are somehow passing in nle as part of the script. It's not, it's an option.

Hi Annihilannic & Era,

Thank you very much for your response, I am really glad you guys are doing great and giving good help.

Specially Era, i am really impress with your personaility, wants to become expert like you, if you dont mind can you give me your email address.

Annihilannic I will check this and update

Thanks,
Bash

Hi Annihilannic & Era,

could you pls help

Thanks,
bash

Please read the rules: do not 'bump up' questions if they are not answered promptly(4)!