我正在尝试像这样解析jquery代码:(这是一个主要部分,但不是全部)
$("#column-wide").css({"background-color":"#eff6f9"});
$("#2626").css({"width":"300px"});
$("#2627").css({"width":"300px"});
$("#2628").css({"width":"300px"});
$("#2629").css({"width":"300px"});
$(".Country > label").css({"position":"relative", "left":"-20px", "top":0});
$("#2631").css({"position":"relative", "left":"-20px", "top":0, "width":128, "height":29});
$("#2633").css({"width":"300px"});
$("#2634").css({"width":"300px"});
// CONTACT INFO BELOW:
$("#2633").css({});
$("#2633").css({"position":"relative", "left":0, "top":0, "width":289, "height":19});
$("#2630").css({"position":"relative", "left":0, "top":0, "width":46, "height":19});
$("#2638").css({"width":"300px"});
$("#2639").css({"width":"300px"});
$(".Prefix").css({"display":"none", "visibility":""});
$(".Last_Name").css({"left":39, "top":3});
$("#2636").css({"position":"relative", "left":49, "top":1});
$("#2640").css({"position":"relative", "left":0, "top":0});
$("#2640").css({"width":"88px"});
$(".State > label").css({"position":"relative", "left":"-60px", "top":0});
$("#2641").css({"position":"relative", "left":"-116px", "top":0});
$("#2641").css({"width":"88px"});
$(".State > label").css({"left":"-121px"});
$("#2641").css({"left":"-161px", "width":98, "height":29});
$("#2637").css({"position":"relative", "left":"5px", "top":0});
$(".State > label").css({"left":"-109px"});
$("#2642").css({"width":"88px"});
$("#2643").css({"width":"88px"});
$(".Alternate_Phone").css({"left":"-129px"});
$(".State > label").css({"left":"-81px"});
$("#2643").css({"position":"relative", "left":"-32px", "top":0});
$(".UserAgreement label").css({"position":"relative", "left":0, "top":0, "width":419, "height":77});
在这样的一行中,虽然只选择带有.css的行,但没有别的:
$('head').append("<style> #2626 { width: 300px; } #2627 { width: 300px; } #2626 { width: 250px; height: 50px; } </style>");
我需要能够抓住第一个#元素,所有行都是.css,然后是变体,例如“width:300px”并将其放入如上所示的单行格式。 我一直试图用bash来做这件事。
#!/bin/bash
echo Enter filename:
read fname
echo "#######"
while read line;do
echo -n "\$('head').append(\"<style> "
awk -F "[)(]" '/.css/{printf "%s %s ",$2,$4}' $fname|sed 's/\"//g;s/,/;/g'
echo -n "</style>\");"
done < $fname
echo "Total number of lines in file: $k"
答案 0 :(得分:1)
#! /usr/bin/bash
echo -n "\$('head').append(\"<style> "
awk -F "[)(]" '/.css/&&/#[0-9]+/{printf "%s %s ",$2,$4}' infile|sed 's/\"//g;s/,/;/g'
echo -n "</style>\");"
结果:
$('head').append("<style> #2626 {width:300px} #2627 {width:300px} #2628 {width:300px} #2629 {width:300px} #2631 {position:relative; left:-20px; top:0; width:128; height:29} #2633 {width:300px} #2634 {width:300px} #2633 {} #2633 {position:relative; left:0; top:0; width:289; height:19} #2630 {position:relative; left:0; top:0; width:46; height:19} #2638 {width:300px} #2639 {width:300px} #2636 {position:relative; left:49; top:1} #2640 {position:relative; left:0; top:0} #2640 {width:88px} #2641 {position:relative; left:-116px; top:0} #2641 {width:88px} #2641 {left:-161px; width:98; height:29} #2637 {position:relative; left:5px; top:0} #2642 {width:88px} #2643 {width:88px} #2643 {position:relative; left:-32px; top:0} </style>");
更新的代码:
#! /usr/bin/bash
echo -n "\$('head').append(\"<style> "
awk -F "[)(]" '/.css/{printf "%s %s ",$2,$4}' infile|sed 's/\"//g;s/,/;/g'
echo -n "</style>\");"
更新了代码#2:
#!/bin/bash
echo Enter filename:
read fname
echo "#######"
echo -n "\$('head').append(\"<style> "
awk -F "[)(]" '/.css/{printf "%s %s ",$2,$4}' $fname|sed 's/\"//g;s/,/;/g'
echo -n "</style>\");"