Jak usunąć wybraną linikę z pliku?

0

Witam, mam pytanie posiadam taki plik:

Ka7877K Katowice 2020-01-23 Kowalski 02
Lo9993L Londyn 2020-01-23 Nowak 02
Lo1046L Londyn 2020-02-11 Pietak 69

Chciałbym usunąć z niego powiedzmy linię drugą:

Lo9993L Londyn 2020-01-23 Nowak 02

ID jest pierwsze, dla tej linii Lo9993L chciałbym ją usunąć z tego pliku jakieś pomysł jak powinienem to zrobić?

Pozdrawiam.

4

cat foo.txt|grep -vE "^Lo9993L" > foo2.txt

1
sed -i "/^Lo9993L/d" foo.txt

sed
sed for windows

1

Jeżeli to windows to może powershell?

Get-Content file.txt | Where { $_ -notmatch "Lo9993L" } | Set-Content filteredfile.txt
0

Chcesz usunąć linijkę z poziomu kodu czy systemu?
Jeśli opcja 2 to jaki system.

0
#include <cstdio>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
   ifstream ifs("delete_file_line.cpp.test");
   ofstream ofs("delete_file_line.cpp.$$$");
   const int drop_line=13;
   string line;
   for(int line_nr=1;getline(ifs,line);++line_nr)
   {
      cout<<"\r"<<line_nr;
      if(line_nr==drop_line) { cout<<endl; continue; }
      ofs<<line<<endl;
   }
   ifs.close();
   ofs.close();
   remove("delete_file_line.cpp.test");
   rename("delete_file_line.cpp.$$$","delete_file_line.cpp.test");
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1