hi,
i have one file as t1.txt as below
hi
hello
welcome
i want perl script to search for the pattern "abcd" in the file.
if the pattern doesn't exist, i want to insert that pattern at the end of the same file t1.txt
my o/p should be
$ cat test
hi
hello
welcome
$ perl -lane 'print $_; $a=1 if $_=~/abcd/; END{if ($a ne 1) {print "abcd"}}' test
hi
hello
welcome
abcd
$ echo "abcd" >> test
$ cat test
hi
hello
welcome
abcd
$ perl -lane 'print $_; $a=1 if $_=~/abcd/; END{if ($a ne 1) {print "abcd"}}' test
hi
hello
welcome
abcd