Marcus
Marcus

Reputation: 49

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"

Upvotes: 1

Views: 1765

Answers (3)

kurumi
kurumi

Reputation: 25599

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

Upvotes: 0

SiegeX
SiegeX

Reputation: 140237

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

Upvotes: 2

bmargulies
bmargulies

Reputation: 100013

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

will do it.

Upvotes: 0

Related Questions