我对awk相当陌生,我的意图是对文件中的以下内容执行模式匹配。 该模式应获取任何具有 vdd *或vss * 的行 我尝试在awk中跟踪模式 vdd ,但是没有用。
if(($1~"inout/svdd") || ($1~"input/svdd") || ($1~"output/svdd")) {
do_something
}
样本输入:
input tprImeasbuf;
output ibias7;
inout vssd;
output vddpminvref;
input disablevdda1v8;
output ibiaspowerreferencescp5;
output vddaok;
input tprImeasPLL;
inout mtp_isense;
output ibiaspowerreferencescp3;
output enablelevelshifts;
output poff;
inout vddp;
input ResGainSel412;
output icasc_ch5;
inout Rref;
output icasc_ch3;
output ibiasshutdowncomparator;
output vdddok;
input tpr_vbgbufout;
output iref3v3_ch4;
inout atb5;
input tprIrefcurbuf;
output ibiaspowerreference4;
input tpr_vdddcompextref;
input tprIrefcurPLL;
预期输出:
vssd
vddpminvref
vddaok
vddp
vdddok
答案 0 :(得分:3)
const layers = ["layer1", "layer2", "layer3"];
async function connect(layer: string): Promise<object> {
return new Promise((resolve, reject) => {
setTimeout(function () {
resolve(layer);
}, 1000);
});
}
(async function () {
for (let i = 0; i < layers.length; i++) {
const result = await connect(layers[i]);
console.log(result, "connected");
}
console.log("All layers are connected");
})();
console.log('Loading function');
const AWS = require('aws-sdk');
const awsConfig = {
region: 'us-west-2',
apiVersion: '2012-08-10',
};
AWS.config.update(awsConfig);
const s3 = new AWS.S3();
const bucket = 'uis-prime-test';
// const uniqueId = Math.floor(Math.random() * 100000);
// initially create the map without any key
const map = {};
function addValueToList(key, value) {
// if the list is already created for the "key", then uses it
// else creates new list for the "key" to store multiple values in it.
map[key] = map[key] || [];
map[key].push(value);
}
function getS3Key(payload) {
const json = JSON.parse(payload);
const creationDateTime = new Date(json.executionContext.creationDateTime);
const year = creationDateTime.getUTCFullYear();
let month = creationDateTime.getUTCMonth() + 1;
const day = creationDateTime.getUTCDate();
const hour = creationDateTime.getUTCHours();
if (month < 10) { month = `0${month}`; }
return `${year}/${month}/${day}/${hour}/`;
}
exports.handler = function (event, context) {
try {
const uniqueId = context.awsRequestId;
event.Records.forEach((record) => {
const payload = Buffer.from(record.kinesis.data, 'base64').toString('ascii');
const key = getS3Key(payload) + uniqueId;
addValueToList(key, payload.toString());
});
Object.entries(map).forEach(([key, value]) => {
const params = { Bucket: bucket, Key: key, Body: value.join('\n') };
s3.putObject(params, (err, data) => {
if (err) {
throw err;
} else {
console.log('Successfully uploaded data');
}
});
});
} catch (err) {
console.log(err);
}
return `Successfully processed ${event.Records.length} records.`;
};
用于处理您发布的样本输入使用$ awk '$2~/^v(ss|dd)/{sub(/;\r$/,"",$2); print $2}' file
vssd
vddpminvref
vddaok
vddp
vdddok
换行符的事实。如果实际输入中不是这种情况,则只需删除\r
。我强烈建议您在文件上运行\r\n
来剥离这些\r
,然后再在其上运行awk或任何其他UNIX工具。
答案 1 :(得分:1)
这是您所期望的吗?
$ awk -F" " ' $0~/vdd|vss/ { print } ' in_file
inout vssd;
output vddpminvref;
input disablevdda1v8;
output vddaok;
inout vddp;
output vdddok;
input tpr_vdddcompextref;
$
EDIT1:
$ awk -F" " ' $1~/input|inout|output/ && $2~/^(vdd|vss)/ { print } ' in_file
inout vssd;
output vddpminvref;
output vddaok;
inout vddp;
output vdddok;
答案 2 :(得分:0)
您可能想使用grep
进行这种简单的模式匹配:
grep -o -E ' v(dd|ss)[^ ;]*' file
-o
用于打印匹配的正则表达式(而不是整行)。
-E
启用扩展正则表达式(ERE)。