[英]Remove the lines starting with a character in shell, but preserve the negative values
我有數據集為:
file.txt
de
fds
fds
a
sa
-1
2
-3
1
}
我想刪除所有以字符或特殊字符開頭的行,但保留負值。 所以我的輸出是:
out.txt
-1
2
-3
1
這個問題與我以前的問題之一有關。 在shell中刪除以字符開頭的行,可以刪除以負號開頭的所有行。
我需要修改我的代碼。
我的代碼:
grep -E "^[0-9].*" file.txt
您可以這樣嘗試:
grep '^ *[-+]\?[0-9]\+' file.txt > out.txt
(要么)
grep -E '^ *[-+]?[0-9]+' file.txt > out.txt
$ grep -E '^[-| ][0-9]' file.txt > out
$ cat out
-1
2
-3
1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.