grep

How to (e) grep XML for certain tag content?

蹲街弑〆低调 提交于 2020-01-15 10:05:26
问题 How can I (e)grep all content between a certain tag block? Assume input file below, I want to get as output all characters between the B-tags so: <B><C>Test</C></B> <B>Test2</B> I tried the following grep to search all XML files with the content between the <B> and </B> tags. grep '<B>.*</B>' *.xml but it did not work. For the following input: <A> <B> <C>Test</C> </B> <D> </D> <B> Test2 </B> </A> Any ideas? 回答1: Use awk: awk '/<B>/,/<\/B>/' 回答2: When working with xml files, the best way is to

How to (e) grep XML for certain tag content?

≡放荡痞女 提交于 2020-01-15 10:01:26
问题 How can I (e)grep all content between a certain tag block? Assume input file below, I want to get as output all characters between the B-tags so: <B><C>Test</C></B> <B>Test2</B> I tried the following grep to search all XML files with the content between the <B> and </B> tags. grep '<B>.*</B>' *.xml but it did not work. For the following input: <A> <B> <C>Test</C> </B> <D> </D> <B> Test2 </B> </A> Any ideas? 回答1: Use awk: awk '/<B>/,/<\/B>/' 回答2: When working with xml files, the best way is to

liunx命令大全

会有一股神秘感。 提交于 2020-01-15 07:30:08
系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS / DMI) hdparm -i /dev/hda 罗列一个磁盘的架构特性 hdparm -tT /dev/sda 在磁盘上执行测试性读取操作 cat /proc/cpuinfo 显示CPU info的信息 cat /proc/interrupts 显示中断 cat /proc/meminfo 校验内存使用 cat /proc/swaps 显示哪些swap被使用 cat /proc/version 显示内核的版本 cat /proc/net/dev 显示网络适配器及统计 cat /proc/mounts 显示已加载的文件系统 lspci -tv 罗列 PCI 设备 lsusb -tv 显示 USB 设备 date 显示系统日期 cal 2007 显示2007年的日历表 date 041217002007.00 设置日期和时间 - 月日时分年.秒 clock -w 将时间修改保存到 BIOS 关机 (系统的关机、重启以及登出 ) shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdown -h hours

Does the argument list pass the string quotes to exec command in C?

蹲街弑〆低调 提交于 2020-01-15 06:31:20
问题 I am using execvp for execing a new process for the command grep -l night * . Here is my code: char * argument[5]; char keyword[] = "night"; argument[0] = (char *) malloc (sizeof(char)*25); argument[1] = (char *) malloc (sizeof(char)*25); argument[2] = (char *) malloc (sizeof(char)*25); argument[3] = (char *) malloc (sizeof(char)*25); argument[4] = (char *) malloc (sizeof(char)*25); argument[0] = "grep"; argument[1] = "-l"; strcpy(argument[2],keyword); argument[3] = "*"; argument[4] = NULL;

linux时间戳

て烟熏妆下的殇ゞ 提交于 2020-01-15 06:15:10
date命令 是显示或设置系统时间与日期。 很多shell脚本里面需要打印不同格式的时间或日期,以及要根据时间和日期执行操作。延时通常用于脚本执行过程中提供一段等待的时间。日期可以以多种格式去打印,也可以使用命令设置固定的格式。在类UNIX系统中,日期被存储为一个整数,其大小为自世界标准时间(UTC)1970年1月1日0时0分0秒起流逝的秒数。 参数 <+时间日期格式>:指定显示时使用的日期时间格式。 日期格式字符串列表 %H 小时,24小时制(00~23) %M 分钟(00~59) %s 从1970年1月1日00:00:00到目前经历的秒数 %S 显示秒(00~59) %T 显示时间,24小时制(hh:mm:ss) %X 显示时间的格式(%H:%M:%S)##shell下的时间加减法就是根据时间戳来实现的,时间戳对我们在shell下的操作非常的有用: 1.计算指定日期的时间戳:date -d "2018-12-05 19:45:44" +%s [machao@iZ233xdnwmfZ ~]$ date -d "2018-12-05 19:45:44" +%s 1544010344 2.计算当天的时间戳:date +%s [machao@iZ233xdnwmfZ ~]$ date +%s 1527833952 3.如果知道某个时间戳,也可以计算出这个时间戳对应的时间日期

For loop in Makefile has no effect

纵饮孤独 提交于 2020-01-15 05:11:26
问题 I have a one-line script passed into the foreach function in a Makefile, as shown below: flag: $(foreach f, $*.txt, printf "%s\n" 0a "$(grep -o '[0-9]\+' $f | sed 's/.*/read \"&\"/')" "" . w q | ed $f) What this script line does could be found here. I am just puzzled why it doesn't work this way, because if I put the line into a separate script and call it from the Makefile like this: flag: $(forech f, $*.txt, ./script $f) it works fine. I also tried the shell for loop as follows: flag: for f

windows下xshell操作Linux命令大全(及服务器日志查看)

隐身守侯 提交于 2020-01-15 05:05:11
( 1 ) 命令ls——列出文件    ls -la 给出当前目录下所有文件的一个长列表,包括以句点开头的“隐藏”文件    ls a * 列出当前目录下以字母a开头的所有文件    ls -l * . doc 给出当前目录下以 . doc结尾的所有文件 ( 2 ) 命令cp——复制文件    cp afile afile . bak 把文件复制为新文件afile . bak    cp afile / home / bible / 把文件afile从当前目录复制到 / home / bible / 目录下    cp * / tmp 把当前目录下的所有未隐藏文件复制到 / tmp / 目录下    cp -a docs docs . bak 递归性地把当前目录下的docs目录复制为新目录docs . bak , 保持文件属性,并复制所有的文件,包括以句点开头的隐藏文件。为了方便起见,-a选项包含-R选项    cp -i 在覆盖前询问用户    cp -v 告诉用户正在做什么 ( 3 ) 命令mv——移动和重命名文件    mv aflie bfile 将afile重命名为bfile    mv afile / tmp 把当前目录下的afile移动到 / tmp / 目录下 ( 4 ) 命令rm——删除文件和目录    rm afile 删除文件afile    rm *

Matching arbitrary number of digits using grep regex

a 夏天 提交于 2020-01-15 03:17:48
问题 I've got a file that has lines in it that look similar as follows data datalater 983290842 Data387428later datafhj893724897290384later 4329804928later What I am looking to do is use regex to match any line that starts with data and ends with later AND has numbers in between. Here is what I've concocted so far: ^[D,d]ata[0-9]*later$ However the output includes all datalater lines. I suppose I could pipe the output and grep -v datalater, but I feel like a single expression should do the trick.

Matching arbitrary number of digits using grep regex

一个人想着一个人 提交于 2020-01-15 03:17:32
问题 I've got a file that has lines in it that look similar as follows data datalater 983290842 Data387428later datafhj893724897290384later 4329804928later What I am looking to do is use regex to match any line that starts with data and ends with later AND has numbers in between. Here is what I've concocted so far: ^[D,d]ata[0-9]*later$ However the output includes all datalater lines. I suppose I could pipe the output and grep -v datalater, but I feel like a single expression should do the trick.

Matching arbitrary number of digits using grep regex

前提是你 提交于 2020-01-15 03:17:25
问题 I've got a file that has lines in it that look similar as follows data datalater 983290842 Data387428later datafhj893724897290384later 4329804928later What I am looking to do is use regex to match any line that starts with data and ends with later AND has numbers in between. Here is what I've concocted so far: ^[D,d]ata[0-9]*later$ However the output includes all datalater lines. I suppose I could pipe the output and grep -v datalater, but I feel like a single expression should do the trick.