-1

cat file | grep "<span class='s-name'>" | awk '/"<span class='s-name'>"/ && /</span>

something about this seems wrong. I mean, other than it's not working.

I also want to put it into a file which I'm pretty sure is just 'filename' at the end.

2 Answers2

0

Using GNU grep

Input

$ cat infile
<div class='signer'> <span class='s-name'>Bob Lepine</span> <span class='s-title'>Vice President of Content, FamilyLife</span> </div>

Output

$ grep -Po "(?<=<span class='s-name'>).*?(?=</span>)" infile
Bob Lepine

$ grep -Po "(?<=<span class='s-title'>).*?(?=</span>)" infile
Vice President of Content, FamilyLife
Akshay Hegde
  • 16,536
  • 2
  • 22
  • 36
0

Using xml/html parsers is the proper way to parse xml/html content, xmlstarlet solution:

xmlstarlet sel -t -v "//span[@class='s-name']" yourfile

The output:

Bob Lepine
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105