-1

I have many files, and I have to find a single line in these files and delete, and should be in terminal in linux. Anyone know how to do?

Example

FileSystem

myFiles
   + file1
   + file2
   ...
   + file6500

The file

aaa0
aaa1
....
fff9
Himanshu
  • 4,327
  • 16
  • 31
  • 39
Alejo Next
  • 383
  • 1
  • 15
  • Can you be more specific? How to do what *exactly*? Remove a single line matching a pattern in every file? What have you tried and where did you get stuck? – Elliott Frisch Apr 14 '15 at 04:25

1 Answers1

1

This would delete that line in each file.

for f in myFiles/*; do
  sed -i 'd/pattern that matches line that you want to delete/' $f
done

Alternatively you could use awk as well.

tmp=$(mktemp)
for f in myFiles/*; do
  awk '!/pattern that matches the line that you want to delete/' $f > $tmp
  cp $tmp $f 
done
rm $tmp

The pattern here would be a regular expression. You can specify different variants of regular expressions, e.g. POSIX or extended by passing different flags to sed or awk. Let me know if this adequately answers your question.

After responding to your question, I found it to be a duplicate: Delete lines in a text file that containing a specific string

Community
  • 1
  • 1
Huarache
  • 246
  • 2
  • 13