如何使用bash或perl解析jquery

如何使用bash或perl解析jquery,jquery,python,parsing,sed,awk,Jquery,Python,Parsing,Sed,Awk,我试图像这样解析jquery代码:(这是主要部分,但不是全部) 在这样的一行中,只选择包含.css的行,而不选择其他行: $('head')。追加('2626{宽度:300px;}2627{宽度:300px;}2626{宽度:250px;高度:50px;}) 我需要能够抓取第一个#元素,所有带有.css的行,然后是变体,例如“width:300px”,并将其放在单行格式中,如上图所示。 我一直在尝试使用bash来实现这一点 #!/bin/bash echo Enter filename: re

我试图像这样解析jquery代码:(这是主要部分,但不是全部)

在这样的一行中,只选择包含.css的行,而不选择其他行:

$('head')。追加('2626{宽度:300px;}2627{宽度:300px;}2626{宽度:250px;高度:50px;})

我需要能够抓取第一个#元素,所有带有.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"
#/bin/bash
输入文件名:
读fname
回声“########”
读行时;做
echo-n“\$('head')。追加(\“”
awk-F“[)(]”“/.css/{printf”%s%s“,$2,$4}'$fname | sed's/\”//g;s/,//;/g”
echo-n“\”;"
完成<$fname
echo“文件中的行总数:$k”
#!/usr/bin/bash
echo-n“\$('head')。追加(\“”
awk-F“[)(]”“/.css/&&/#[0-9]+/{printf”%s%s“,$2,$4}”infle | sed's/\”//g;s/,/;/g'
回声-n“\”
结果:

$('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>");
[代码>:(“头部”)码>,(“头部”是一名,(“头部”)是一名,(“头部”)是一名,(“头部”代码>,(“头部”)是一名,(“头部”代码>,(“头部”)是一名,((“#码码码码码码码码>>)码(((“#2626 6{{6{{6{{6{6{{6{6{6{6{宽度:宽度:宽度:300:300px:300px码码码码码码码))周五周五周五(((([[[[宽度:300::::::[[[[[[[[[[[''''''''''''''''''''''''''''''码码码码码码码码码码码码码))))))))是(((“(“(“(“(“(“(“9;高度:19}#2630{位置:相对;左侧:0;顶部:0;宽度:46;高度:19}3月26日{位置:相对;左:49;顶部:1}周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五{宽度:300px}周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五周五顶部:0}2642{宽度:88px}2643{宽度:88px}2643{位置:相对;左:-32px;顶部:0}”);
更新代码:

#! /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>\");"
!/usr/bin/bash
echo-n“\$('head')。追加(\“”
awk-F“[)(]”“/.css/{printf”%s%s“,$2,$4}”infle | sed's/\”//g;s/,//;/g'
回声-n“\”
更新代码#2:

!/bin/bash
输入文件名:
读fname
回声“########”
echo-n“\$('head')。追加(\“”
awk-F“[)(]”“/.css/{printf”%s%s“,$2,$4}'$fname | sed's/\”//g;s/,//;/g”
回声-n“\”

如果你在标题中说你想使用bash或perl,为什么这个标签是“python”?使用python也是可以接受的-很抱歉混淆了!它们来自哪里:#2626{width:250px;height:50px;}我把它作为输出:$('head').append(“awk:cannotopenfileinfire sourceline number 1”);$('head')).append(“awk:无法打开文件填充源代码行1”);$('head')。append(“awk:无法打开文件填充源代码行1”);$('head')。append(“awk:无法打开文件填充源代码行1”);$('head')。append(“awk:无法打开文件infle使用您的文件名替换infle,infle是我的测试文件名。我想我可能会让它用于更简单的操作;#2626,#2627并获取其操作-但是使用多个字符串的操作呢?$(#列宽”).css({“背景色”:“#eff6f9”}$(#2626”).css({“宽度”:“300px”})$(#2627”).css({“宽度”:“300px”});$(“#2628”).css({“宽度”:“300px”});$(“#2629”).css({“宽度”:“300px”});$(“.Country>标签”).css({“位置”:“相对”,“左”:-20px”,“顶”:0})$(“#2631”).css({“位置”:“相对”,“左”:-20px”,“顶”:0,“宽度”:128,“高度”:29});您需要提供所有可能的示例,并在原始问题中进行编辑。非常感谢您的帮助BMW-我已经添加了需要解析的大部分文件-但它仍然不是全部。我将使这成为一个标准化脚本,因此我希望它能够成为未来的证明,无论解析的是什么(尽管它将始终是.css)无论我获取的是类或id“#”或“.”,还是运算符的数量“宽度:xx高度:xx位置,等等”
$('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>\");"
#!/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>\");"