1820568 Members
2010 Online
109626 Solutions
New Discussion юеВ

script

 
SOLVED
Go to solution
U.SivaKumar_2
Honored Contributor

script

Hi,
I have a file called test.txt (1000 lines)in unix with cotents.
a.b
f.c
d.b
b.h
j.k
...
...
How can I delete a specific pattern example
j.k in this file by shell script.

regards,
U.SivaKumar
Innovations are made when conventions are broken
8 REPLIES 8
Tom Geudens
Honored Contributor
Solution

Re: script

Hi,
cat [filename] | awk '!/j\.k/ { print }'

Is that what you are looking for ?

Regards,
Tom
A life ? Cool ! Where can I download one of those from ?
Stanley Merkx
Advisor

Re: script


What about grep -v '^j.k' test.txt ?

Or are you looking for more complex pattern matching?

Stanley.
Leif Halvarsson_2
Honored Contributor

Re: script

Hi
If this pattern is alone on a line:
grep -v j.k
Tommy Palo
Trusted Contributor

Re: script

This is one way to do it.

#!/usr/bin/ksh
PATTERN=j.k
cat - << EOF | ed -s test.txt
/$PATTERN
d
w
q
EOF
Keep it simple
H.Merijn Brand (procura
Honored Contributor

Re: script

# perl -ne '/j\.k/||print' infile
Enjoy, Have FUN! H.Merijn
Procnus
Frequent Advisor

Re: script

Off the command line:
sed -e '/j.k/d' test.txt

In a script:
#!/usr/bin/ksh

eval sed -e '/$1/' test.txt

#end script

Then invoke as ./script.sh j.k

Cheers
Steven
Procnus
Frequent Advisor

Re: script

Oops...
#!/usr/bin/ksh

eval sed -e '/$1/d' test.txt

#end script

Then invoke as ./script.sh j.k


Steven
U.SivaKumar_2
Honored Contributor

Re: script

Was expecting a sed solution too.
regards,
U.SivaKumar
Innovations are made when conventions are broken