1

我想在这些行中显示最后一个单词我试图寻找例如单词值但没有答案,所以我想查找引号之间的单词但是我的文件包含引号之间的其他单词我实际上不需要在知道我的html文件是的情况下显示select标签的值。

grep '*' hosts.html | awk '{print $NF}'

例如:

value='www.visit-tunisia.com'>www.visit-tunisia.com 
value='www.watania1.tn'>www.watania1.tn 
value='www.watania2.tn'>www.watania2.tn 

我会

www.visit-tunisia.com 
www.watania1.tn 
www.watania2.tn 
4

3 回答 3

0

You need to set the field separator to > you do this with the -F option:

$ awk -F'>' '{print $NF}' hosts.html
www.visit-tunisia.com
www.watania1.tn
www.watania2.tn

Note: I'm not sure what you are trying to achieve by grep '*' hosts.html?

于 2013-03-25T10:38:31.973 回答
0

Interpreting the comment liberally, you have input lines which might contain:

value='www.visit-tunisia.com'>www.visit-tunisia.com
value='www.watania1.tn'>www.watania1.tn
value='www.watania2.tn'>www.watania2.tn

and you would like the names which are repeated on a line as the output:

www.visit-tunisia.com
www.watania1.tn
www.watania2.tn

This can be done using sed and capturing parentheses.

sed -n -e "s/.*'\([^']*\)'.*\1.*/\1/p"

The -n says "don't print unless I say to do so". The s///p command prints if the substitute works. The pattern looks for a stream of 'anything' (.*), a single quote, captures what's inside up to the next single quote ('\([^']*\)') followed by any text, the captured text (the first \1), and anything. The replacement text is what was captured (the second \1).

Example:

$ cat data
www and wotnot
value='www.visit-tunisia.com'>www.visit-tunisia.com
blah
value='www.watania1.tn'>www.watania1.tn
hooplah
value='www.watania2.tn'>www.watania2.tn
if 'nothing' is required, nothing will be done.
$ sed -n -e "s/.*'\([^']*\)'.*\1.*/\1/p" data
www.visit-tunisia.com
www.watania1.tn
www.watania2.tn
nothing
$

Clearly, you can refine the [^']* part of the match if you want to. I used double quotes around the expression since the pattern matches on single quotes. Life is trickier if you need to allow both single and double quotes; at that point, I'd put the script into a file and run sed -f script data to make life easier.

于 2013-03-25T10:38:43.817 回答
0
sed 's/.*>\(.*\)/\1/g' your_file
于 2013-03-25T11:09:40.387 回答