我有一个使用以下语法的文件:
key1 | key2 | key31:value31, key32:value32, ...| key4
我想过滤第三部分中具有特定键和值的所有行。
例如,在下面的测试中,我希望过滤所有年龄= 13的行,更多我想用$ 3的用户键进行过滤,例如使用密钥年龄和年龄> = 15。
GET|20150715|age:13,height:11,width:12|Mike
POST|20150715|age:13,width:11|Tom
GET|20150715|height:11,width:11|Lily
我可以使用awk来做这件事吗?
答案 0 :(得分:2)
awk -F'|' '$3~/age:13/' file
这是"脏"因为,如果某人已经足够年长,请说age:135
,它也会被列出,如果age:13
中没有$3
,但package:13
该行将被输出为awk -F'|' -v value="12"
'$3~/age:/{v=gensub(".*age:([0-9]*).*","\\1","G",$3);if(v>value)print}' file
好。但是这个单行快速拍摄,你可以试试它是否适合你的真实数据。
-v value="12"
15, 17....
更改为您要检查的值条件,例如if(v... value)
<13
检查。以下是一个测试版,其中包含一行年龄值kent$ cat f
GET|20150715|age:13,height:11,width:12|Mike
xxxGET|20150715|age:10,height:11,width:12|Mike
POST|20150715|age:13,width:11|Tom
GET|20150715|height:11,width:11|Lily
kent$ awk -F'|' -v value="12" '$3~/age:/{v=gensub(".*age:([0-9]*).*","\\1","G",$3);if(v>value)print}' f
GET|20150715|age:13,height:11,width:12|Mike
POST|20150715|age:13,width:11|Tom
:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using System.IO;
using System.Globalization;
using System.Threading;
namespace New
{
public partial class Servers : System.Web.UI.Page
{
string oradb = "Data Source=(DESCRIPTION =" + "(ADDRESS = (PROTOCOL = TCP)(HOST = hqidlbmcdb50.hqh.intra.aexp.com)(PORT = 1521))" + "(CONNECT_DATA =" + "(SERVER = DEDICATED)" + "(SERVICE_NAME = TSOBMC0P)));" + "User Id=MyId;Password=Mypass;";
protected void Page_Load(object sender, EventArgs e)
{
try
{
OracleConnection con = new OracleConnection(oradb);
OracleCommand cmd = new OracleCommand();
cmd.CommandText = "select DISTINCT hostname from PE.NODE where HOSTNAME like '%bas%' ORDER BY hostname ASC";
cmd.Connection = con;
con.Open();
OracleDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
Response.Write("<div >");
Response.Write("<table border='1'>");
Response.Write("<tr><th>HOST NAME</th></tr>");
while (dr.Read())
{
Response.Write("<tr>");
Response.Write("<td>" + dr["HOSTNAME"].ToString() + "</td>");
Response.Write("</tr>");
}
Response.Write("</table>");
Response.Write("</div>");
}
else
{
Response.Write("No Data In DataBase");
}
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}