Windows command line/shell - While appending file

2019-08-17 10:58发布

I'm not familiar with Windows shell. So, let's say my file is like:

DontAppend this line shouldn't be appended
DontAppend this line shouldn't be either
Some lines
more lines

And I'm appending like this:

type file.txt >> AppendHere.txt

This appends the whole file. How do I make it so it skips lines that begin with "DontAppend"?

2条回答
Lonely孤独者°
2楼-- · 2019-08-17 11:24

Either get grep for windows or you could use Windows' own find command

type so.txt|find /v "DontAppend" >> output.txt

The /v option means output lines that dont match your string.

find works for very simple things like this but any more you will need a real filtering tool like grep

查看更多
\"骚年 ilove
3楼-- · 2019-08-17 11:26

The command findstr will let you search for lines not containing a string or regular expression so you can use:

findstr /vrc:"^[^A-Za-z0-9]*DontAppend" file.txt >> AppendHere.txt

The /r option says it should use regular expressions and the caret (^) says it should begin with the string.

Edit: added a filter for non alphanumeric chars that may solve the Unicode issues (Unicode files sometimes have a non-printable indicator characters in the beginning).

查看更多
登录 后发表回答