0

I am using sed to read the .css file name (after "href=") from an html file. The command is follow:

cssFiles=$(echo "$BODY" | sed -rn 's/<link\s.*href=\W(.*.css).*/\1/p')

But, it does not works correctly. Below, sample input, output and expected output is given. Where am I wrong?

Sample input:

<link href="/css/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="js/flexslider/flexslider.css">

Sample output:

/css/default.css" rel="stylesheet" type="text/css
js/flexslider/flexslider.css

Expected output:

/css/default.css
js/flexslider/flexslider.css

1 Answer 1

1

Try this:

cssFiles=$(echo "$BODY" | sed -rn 's/<link\s.*href=\W(.*.css).*/\1/p' | awk -F'=' '{print$2}'  awk -F' ' '{print$1}')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.