Hi
I have 3 files and I want to remove 1 line in each file. This line correposnds to the occurrence of a specific pattern
any idea how to do this in shell?
thx
Hi
I have 3 files and I want to remove 1 line in each file. This line correposnds to the occurrence of a specific pattern
any idea how to do this in shell?
thx
sounds like 'sed' would be a good starting point.
what have you tried so far?
Use search, this solutions has told so many times using grep, sed, awk, perl, shell ex. case, ...
No need to use shell, simple commandline using cmd grep is enough:
ex.
grep -v "removedatapattern" infile > resultfile
First make backups of your files.
Does each file have the same pattern? If so,
sed -i '/PATTERN/d' file1 file2 file3
Now this might remove MULTIPLE lines in each file matching the pattern. If that's unacceptable, you can use awk this way:
for m in file1 file2 file3; do
awk 'fixed && /PATTERN/ { fixed=1; next; } { print }' $m .~$m.$$
mv .~$m.$$ $m
done
There might be a way to do this in sed too.
try:
perl -i -e ' while(<>) { unless (/pattern/) {print; }} ' file1 file2 ...