Question: I have several text files where each line starts with a group code, and each data item is separated by pipe characters. There is a specific group that will sometimes have data, and sometimes have no data, and will therefore only have the group code and pipes. I am trying to remove these groups with no data, while keeping the ones that do have data.

For example, two lines in my file would look like:

```
A01|ABC|123|XYZ|
A05|123456789||
A05|||
A01|DEF|456|UVW|
A05|987654321||
A05|||
A08|SOMEDATA|

```

I want it to look like

```
A01|ABC|123|XYZ|
A05|123456789||
A01|DEF|456|UVW|
A05|987654321||
A08|SOMEDATA|

```

I have tried to use findstr, as below:

```
type MYFILE.txt | findstr /v "A05|||" > MYFILE.txt

```

however this is deleting everything from the file, rather than just lines containing A05|||

Answer: 
Try using another file:

```
FindStr/RV "^A05||" MyFile.txt>AnotherFile.txt

```

Then if needs be **del**ete **Myfile.txt** & **ren**ame **AnotherFile.txt MyFile.txt**
You are almost there, but there are two issues in your command line:

```
type MYFILE.txt | findstr /v "A05|||" > MYFILE.txt

```

1. The redirection `> MYFILE.txt` is applied to the entire command line, so when redirection is prepared, the (new) empty file `MYFILE.txt` is created first, then the command line is executed. To avoid that, redirect the output to another file and move this onto the original one afterwards.
2. The search string matches only lines beginning with `A05`, but not something like `A06|||`. To match such lines also, change the search string to `|||$` (`$` anchors the match to the end). In case the number of fields may vary, you could use this: `^[^|]*|*$` (meaning any number of characters other than `|` as group code, followed by any number of adjacent `|`; the `^` at the beginning anchors the match to the beginning of the line; together with the `$` that anchors the match to the end, it enforces the entire line to match the given pattern).

Hence the corrected command line looks like this:

```
type "MYFILE.txt" | findstr /V "|||$" > "MYFILE.txt.tmp" & move /Y "MYFILE.txt.tmp" "MYFILE.txt" > nul

```

Or, with the alternative search string for a variable number of fields:

```
type "MYFILE.txt" | findstr /V "^[^|]*|*$" > "MYFILE.txt.tmp" & move /Y "MYFILE.txt.tmp" "MYFILE.txt" > nul

```

The quotation marks around the file path/name are just inserted to yield a more general syntax, which does not fail even in case white-spaces or some other poisonous characters occur.