当前位置: 首页 > 编程日记 > 正文

GNU AWK中BEGIN/END使用举例

以下是使用gnu awk将test.cpp文件拆分成两个文件a.cpp和b.cpp,其中b.cpp仅存放test.cpp中的数据,其它内容存放在a.cpp文件中。

test.cpp内容如下:

#include <stdio.h>
#include <iostream>
#include <string>int main()
{// face size: [20, 30, 200, 400](x, y, width, height), detection time in 50 ms.// eye size: [5, 5, 10, 10](x, y, width, height), detection time in 10 ms.const std::string blog_name = "https://blog.csdn.net/fengbingchun";unsigned char t = 4;const unsigned char _xx[5] __attribute__((aligned(64))) = { 0x02, 0x32, 0x42, 0x32, 0x69 };typedef struct {int x, y, width, height;float score;} rect;const unsigned char _yy[7]  __attribute__((aligned(64))) = {0x12, 0x23, 0x54, 0x89,0x01, 0x09, 0x26};const std::string github_name = "https://github.com/fengbingchun";const unsigned char _zz[3] __attribute__((aligned(64))) = {0x23, 0x78, 0x15};fprintf(stdout, "ok\n");return 0;
}

test.awk内容如下:

#! /bin/bash/awkBEGIN {# 在BEGIN中FILENAME不起作用print "// ===== start process file: " ARGV[1]# author为外部传进来的变量名print "// Author: " authorstate = 0offset = 0
}{if (match($0, "blog_name .* \"(.*)\"", s)) {blog = s[1]}if (match($0, "github_name .* \"(.*)\"", s)) {github = s[1]}if (FNR == 1) {print "// file name: " file1 > file1print "// Author: " author >> file1print "// ===== start process file: " FILENAME >> file1print "" >> file1print "// file name: " file2 > file2print "// Author: " author >> file2print "// ===== start process file: " FILENAME >> file2print "" >> file2print "unsigned char data[] = { " >> file2}if (state == 0 && $0 ~ "^    const unsigned char") {state = 1pos0 = index($0, "_")pos1 = index($0, "[")pos2 = index($0, "]")name = substr($0, pos0, pos1 - pos0)offsetstr = substr($0, pos1 + 1, pos2 - pos1 - 1)offsetl = 0 + offsetstrif (offsetl % 64 != 0) {remain = 64 - offsetl % 64} else {remain = 0}print "    const unsigned char* "name" = NULL;" >> file1print "    const unsigned int "name"_offset = " offset ";" >> file1offset += (offsetl + remain);print "// start data: " name >> file2} else if (state == 1) {if ($0 ~ "^    };") {print "// end data: " name >> file2;print "," >> file2print "// "name" remain: " remain >> file2;for (i = 0; i < remain; ++i) {printf("0x00, ") >> file2;}print "" >> file2state = 0;} else {print $0 >> file2}} else {print $0 >> file1}
}END {printf "};\n\n" >> file2print "// blog: "blog" " >> file1print "// github: "github" " >> file2print "// ===== end process file: " FILENAMEprint "// ===== end process file: " FILENAME >> file1print "// ===== end process file: " FILENAME >> file2
}

在mark.sh文件中添加一句:

awk -f test.awk -v author="fengbingchun"  -v file1="a.cpp" -v file2="b.cpp" test.cpp

执行mark.sh:$ ./mark.sh

自动生成的a.cpp文件如下:

// file name: a.cpp
// Author: fengbingchun
// ===== start process file: test.cpp#include <stdio.h>
#include <iostream>
#include <string>int main()
{// face size: [20, 30, 200, 400](x, y, width, height), detection time in 50 ms.// eye size: [5, 5, 10, 10](x, y, width, height), detection time in 10 ms.const std::string blog_name = "https://blog.csdn.net/fengbingchun";unsigned char t = 4;const unsigned char* _xx = NULL;const unsigned int _xx_offset = 0;typedef struct {int x, y, width, height;float score;} rect;const unsigned char* _yy = NULL;const unsigned int _yy_offset = 64;const std::string github_name = "https://github.com/fengbingchun";const unsigned char* _zz = NULL;const unsigned int _zz_offset = 128;fprintf(stdout, "ok\n");return 0;
}// blog: https://blog.csdn.net/fengbingchun 
// ===== end process file: test.cpp

自动生成的b.cpp文件内容如下:

// file name: b.cpp
// Author: fengbingchun
// ===== start process file: test.cppunsigned char data[] = { 
// start data: _xx0x02, 0x32, 0x42, 0x32, 0x69 
// end data: _xx
,
// _xx remain: 59
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// start data: _yy0x12, 0x23, 0x54, 0x89,0x01, 0x09, 0x26
// end data: _yy
,
// _yy remain: 57
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// start data: _zz0x23, 0x78, 0x15
// end data: _zz
,
// _zz remain: 61
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};// github: https://github.com/fengbingchun 
// ===== end process file: test.cpp
GitHub: https://github.com/fengbingchun/Linux_Code_Test

相关文章:

目标检测的渐进域自适应,优于最新SOTA方法

作者 | Han-Kai Hsu、Chun-Han Yao、Yi-Hsuan Tsai、Wei-Chih Hung、Hung-Yu Tseng、Maneesh Singh、Ming-Hsuan Yang译者 | 刘畅编辑 | Jane出品 | AI科技大本营&#xff08;ID&#xff1a;rgznai100&#xff09;【导读】目标检测的最新深度学习方法依赖于大量的边界框标注信息…

讨论下IDS的绕过

自从知道dedecms自带了80sec的内置Mysqlids后&#xff0c;一直以来也没有想到绕过的办法。或者是自己mysql的根底太差了吧。于是分析dedecms源码时&#xff0c;只找模板执行&#xff0c;本地包含&#xff0c;上传等&#xff0c;完全没有想到注入存在的可能性了。 可以看看某牛的…

GCC编译选项参数介绍

gcc和g分别是gnu的c和c编译器&#xff0c;下面是整理的常用编译选项参数&#xff1a; #(1). -x: 设定文件所使用的语言&#xff0c;使文件后缀名无效&#xff0c;如下&#xff0c;执行完后生成test.o gcc -c -x c test.jpg #(2). -c: 只编译生成目标文件即*.o,只编译不链接生成…

程序员自学到底有没有用?网友们吵翻了...

最近就有个程序员吐槽说&#xff0c;自己大学没怎么听老师讲课&#xff0c;老师讲的知识要么太旧&#xff0c;要么老师不会讲&#xff0c;自己大部分时间是在网上看视频学的。引发了以下激烈的讨论。很多网友觉得&#xff0c;学校老师的代码能力不行&#xff0c;现在技术更新又…

更新 FrameWork

这里把想要改变的东西封装到FrameWork以便实现热更新&#xff0c;提一下关于BundiD 一定要一致&#xff0c;在打包的时候一定在Edit scheme —— >Run 选择Release如图&#xff1a; 因为你要跑在真机上&#xff0c;所以这个要选择Release 另外将包含你想要放出的方法类添加…

把Illustrator矢量图转化为代码:Drawscript

2019独角兽企业重金招聘Python工程师标准>>> DrawScript是一款Illustrator插件&#xff0c;可以将Illustrator的矢量图片转换成代码&#xff0c;目前免费&#xff0c;支持转换的语言有 OBJ-CCJAVASCRIPTCREATEJS/EASELJSPROCESSINGACTIONSCRIPT 3JSONRAW BEZIER PO…

必读:ICLR 2020 的50篇推荐阅读论文

来源 | 香侬科技本文整理了ICLR2020的相关论文&#xff0c;此次分享的是从Openreview中选取的部分论文&#xff0c;共50篇&#xff0c;其中大部分为NLP相关。文中涉及的相关论文推荐指数与推荐理由仅为个人观点&#xff0c;利益无关&#xff0c;亦不代表香侬科技立场。希望大家…

14个Xcode中常用的快捷键操作

在Xcode 6中有许多快捷键的设定可以使得你的编程工作更为高效&#xff0c;对于在代码文件中快速导航、定位Bug以及新增应用特性都是极有效的。 当然&#xff0c;你戳进这篇文章的目的也在于想要快速的对代码文件进行操作&#xff0c;或者是让Xcode的各面板更为适应你小本子的屏…

C++中标准模板库std::pair的实现

以下用C实现了标准模板库中的std::pair实现&#xff0c;参考了 cplusplus 和 vs2013中的utility文件。关于std::pair的介绍和用法可以参考&#xff1a; https://blog.csdn.net/fengbingchun/article/details/52205149 实现代码pair.hpp如下&#xff1a; #ifndef FBC_STL_PAIR_H…

【人在职场】能力与价值

原创作品&#xff0c;允许转载&#xff0c;转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://yunli.blog.51cto.com/831344/1547051 最近给团队&#xff08;指#UC浏览器电脑版#开发团队&#xff09;分享了我的《基层技术管理原则》。…

Windows与Linux之间互传文件的方法

以下方法均是以Windows为操作机&#xff1a;1. 通过WinSCP:WinSCP是一款开源的SFTP客户端&#xff0c;运行于Windows系统下&#xff0c;遵照GPL发布。WinSCP除了SFTP&#xff0c;还支持SSH、SCP(SecureCopy Protocol)。WinSCP的开发始于2000年4月&#xff0c;由布拉格经济大学所…

一文读懂简化的图卷积网络GCN(SGC)| ICML 2019

作者 | yyl424525来源 | CSDN博客文章目录1 相关介绍1.1 Simple Graph Convolution (SGC)提出的背景1.2 SGC效果2 Simple Graph Convolution 简化的图卷积2.1 符号定义2.2 图卷积网络GCNGCN vs MLPFeature propagation 特征传播Feature transformation and nonlinear transitio…

iOS UITableViewCell重用问题

TableView的重用机制&#xff0c;为了做到显示和数据分离&#xff0c;iOS tableView的实现并且不是为每个数据项创建一个tableCell。而是只创建屏幕可显示最大个数的cell&#xff0c;然后重复使用这些cell&#xff0c;对cell做单独的显示配置&#xff0c;来达到既不影响显示效果…

NLP常用工具

为什么80%的码农都做不了架构师&#xff1f;>>> NLP常用工具 各种工具包的有效利用可以使研究者事半功倍。 以下是NLP版版友们提供整理的NLP研究工具包。 同时欢迎大家提供更多更好用的工具包&#xff0c;造福国内的NLP研究。 *NLP Toolbox CLT http://compl…

Swift快速入门之getter 和 setter

属性可以用getter和setter方法的形式提供。 <code class"hljs lasso has-numbering" style"display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: Source Code Pro, monospace;font-size:u…

Linux下getopt函数的使用

getopt为解析命令行参数函数&#xff0c;它是Linux C库函数。使用此函数需要包含系统头文件unistd.h。 getopt函数声明如下&#xff1a; int getopt(int argc, char * const argv[], const char * optstring); 其中函数的argc和argv参数通常直接从main的参数直接传递而来。o…

20行Python代码说清“量子霸权”

作者 | 马超 来源 | 程序人生&#xff08;ID:coder_life&#xff09;近日谷歌的有关量子霸权&#xff08;Quantum Supremacy&#xff09;的论文登上了Nature杂志150年刊的封面位置&#xff0c;而再次罢占各大媒体的头条位置&#xff0c;其实这篇文章之前曾经短暂上过NASA的网站…

Android组件系列----BroadcastReceiver广播接收器

​【声明】 欢迎转载&#xff0c;但请保留文章原始出处→_→ 生命壹号&#xff1a;http://www.cnblogs.com/smyhvae/ 文章来源&#xff1a;http://www.cnblogs.com/smyhvae/p/3960623.html 【正文】 一、广播的功能和特征 广播的生命周期很短&#xff0c;经过调用对象-->…

Swift 代码调试-善用XCode工具(UI调试,五种断点,预览UIImage...)

原创Blog&#xff0c;转载请注明出处 http://blog.csdn.net/hello_hwc?viewmodelist 我的stackoverflow 工欲善其事&#xff0c;必先利其器&#xff0c;强烈建议新手同学好好研究下XCode这个工具。比如Build Settings&#xff0c;Build Info Rules&#xff0c;Build Parse…

Linux下getopt_long函数的使用

getopt_long为解析命令行参数函数&#xff0c;它是Linux C库函数。使用此函数需要包含系统头文件getopt.h。 getopt_long函数声明如下&#xff1a; int getopt_long(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex);…

Expect自动化控制简单介绍

telnet&#xff0c;ftp&#xff0c;Passwd&#xff0c;fsck&#xff0c;rlogin&#xff0c;tip&#xff0c;ssh等等。该工具利用Unix伪终端包装其子进程&#xff0c;允许任意程序通过终端接入进行自动化控制&#xff1b;也可利用Tk工具&#xff0c;将交互程序包装在X11的图形用…

C++中标准模板库std::vector的实现

以下实现了C标准模板库std::vector的部分实现&#xff0c;参考了 cplusplus. 关于C中标准模板库std::vector的介绍和用法可以参考 https://blog.csdn.net/fengbingchun/article/details/51510916 实现代码vector.hpp内容如下&#xff1a; #ifndef FBC_STL_VECTOR_HPP_ #defi…

Swift学习 OOP三大特性:继承、多态、封装

先看个例子 从上面的例子可以总结那么一句话:”学生是人”。也就是Student类继承People类。简而言之&#xff0c;学生是人&#xff0c;这句话是说得通的&#xff0c;但是”人是学生”这句话是说不通的&#xff0c;不是学生就不是人了嘛? 从代码中&#xff0c;我们可以看出S…

5折票倒计时3天 | 超干货议程首度曝光!2019 中国大数据技术大会邀您共赴

&#xff08;大会官网https://t.csdnimg.cn/U1wA&#xff09;2019年&#xff0c;大数据与人工智能的热度已经蔓延到了各个领域&#xff0c;智能交通、AIoT、智慧城市&#xff0c;智慧物流、AI中台、工业制造等各种黑科技成为热搜名词。而在今年的乌镇互联网大会上&#xff0c;大…

mysql select * f

mysql> select * from tb;-------------| id | name |-------------| 1 | tbone || 3 | 2d2 || 5 | 55 || 6 | 66 |-------------4 rows in set (0.00 sec)转载于:https://www.cnblogs.com/bashala/p/3974088.html

C++/C++11中用于定义类型别名的两种方法:typedef和using

类型别名(type alias)是一个名字&#xff0c;它是某种类型的同义词。使用类型别名有很多好处&#xff0c;它让复杂的类型名字变得简单明了、易于理解和使用&#xff0c;还有助于程序员清楚地知道使用该类型的真实目的。在C中&#xff0c;任何有效类型都可以有别名。 有两种方法…

iOS学习笔记--01swift实现提示框第三方库:MBProgressHUD

本文使用swift语言使用MBProgressHUD。 开源项目MBProgressHUD可以实现多种形式的提示框。使用简单&#xff0c;方便。GitHud的下载地址是&#xff1a;https://github.com/jdg/MBProgressHUD/ 下载完成后&#xff0c;将MBProgressHUD.h和MBProgressHUD.m拖入已经新建好的Swift项…

2019北京智源大会在京开幕, 中外学术大咖共话人工智能研究前沿

10月31日&#xff0c;由北京智源人工智能研究院主办的2019北京智源大会在国家会议中心开幕&#xff0c;会期两天。智源大会是北京创建全球人工智能学术和创新最优生态的标志性学术活动&#xff0c;定位于“内行的AI盛会”&#xff0c;以国际性、权威性、专业性和前瞻性为特色&a…

linux中登录类型及配置文件

linux中登录shell的类型1.交互式登录&#xff1a;直接通过终端输入用户信息登录1&#xff09;login&#xff1a;2&#xff09;在shell中 su - usernamesu -l username2.非交互式登录1&#xff09;su username2&#xff09;图形界面的终端3&#xff09;执行脚本的过程用户配置文…

Swift项目引入第三方库的方法

分类&#xff1a;iOS&#xff08;55&#xff09; 目录(?)[] Swift项目引入第三方库的方法 转自 http://blog.shiqichan.com/How-To-Import-3rd-Lib-Into-Swift-Project/ 以下&#xff0c;将创建一个Swift项目&#xff0c;然后引入3个库&#xff1a; Snappy 简化autolayout代码…