开发者

Print specific lines using sed

Im开发者_运维百科 trying to print only lines that do not start with a letter from the file "main"

Ive tried sed -n '/^[a-z]/ /!w' main and it gives me "w': event not found"


With sed as requested:

sed '/^[[:alpha:]]/d' main

or

sed -n '/^[^[:alpha:]]/p' main

or

sed -n '/^[[:alpha:]]/!p' main

Note: you could use [a-z] inplace of [[:alpha:]] but I prefer the latter because it is safe to use across different locales


there are many other ways to print lines

sed -n '/^[^a-zA-Z]/p' main
sed -n '/^[^a-z]/Ip' main 

awk 'BEGIN{IGNORECASE=1}!/^[a-z]/' main

grep -vi "^[a-z]" main

ruby -ne 'print unless /^[a-z]/i' main

shell

while read -r line
do
  case "$line" in
    [^a-zA-Z]*) echo $line;;
  esac
done < main


grep -v '^[a-z]' main

will do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜