Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print all words that start with a %, one to a line.

Status
Not open for further replies.

jfm1

Technical User
Mar 29, 2000
3
US
Hello,

I have a log where every line has a word in it that starts with a % sign. I need to print each line, but only the word that starts with %, no other words or characters.

Thanks for your help,

Joe
 
Hey, Joe

It's easier just to use sed for this one.

cat logfile | sed '/^\%/!d'

Will give you the output that you want.
 
Sorry, I misunderstood what you wanted.
Assuming the wortds are separated by a space
then you could write this in awk and it would
work.

cat logfile | awk ' {
split($0, per, " ")
for (i in per)
if ($i ~ /^\%/) {
print $i
}
}'

Bye now.
 
I tried that but in csh I got "d': Event not found" as an error msg. But I tried combining sed and awk and finally got what I wanted:

cat logfile | sed 's/.*\(%\)/\1/' | awk '{print $1}'

This listed the "%words" I was looking for. Thanks for the kick start.

Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top