首页 > 其他分享 >sed-每行提取特定字符,下行添加内容

sed-每行提取特定字符,下行添加内容

时间:2024-12-19 18:09:35浏览次数:3  
标签:字符 00 每行 option 0x00 system filename sed pxe

# 文件内容
cat dhcpcode93配置.txt 
# Type,Architecture Name,Reference
# 0x00 0x00,x86 BIOS,[RFC5970][RFC4578]
# 0x00 0x01,NEC/PC98 (DEPRECATED),[RFC5970][RFC4578]
# 0x00 0x02,Itanium,[RFC5970][RFC4578]
# 0x00 0x03,DEC Alpha (DEPRECATED),[RFC5970][RFC4578]
# 0x00 0x04,Arc x86 (DEPRECATED),[RFC5970][RFC4578]
# 0x00 0x05,Intel Lean Client (DEPRECATED),[RFC5970][RFC4578]
# 0x00 0x06,x86 UEFI,[RFC5970][RFC4578]
# 0x00 0x07,x64 UEFI,[RFC5970][RFC4578]
# 0x00 0x08,EFI Xscale (DEPRECATED),[RFC5970][RFC4578]
# 0x00 0x09,EBC,[RFC5970][RFC4578]
# 0x00 0x0a,ARM 32-bit UEFI,[RFC5970]
# 0x00 0x0b,ARM 64-bit UEFI,[RFC5970]
# 0x00 0x0c,PowerPC Open Firmware,[Thomas_Huth]
# 0x00 0x0d,PowerPC ePAPR,[Thomas_Huth]
# 0x00 0x0e,POWER OPAL v3,[Jeremy_Kerr]
# 0x00 0x0f,x86 uefi boot from http,[Samer_El-Haj-Mahmoud]
# 0x00 0x10,x64 uefi boot from http,[Samer_El-Haj-Mahmoud]
# 0x00 0x11,ebc boot from http,[Samer_El-Haj-Mahmoud]
# 0x00 0x12,arm uefi 32 boot from http,[Samer_El-Haj-Mahmoud]
# 0x00 0x13,arm uefi 64 boot from http,[Samer_El-Haj-Mahmoud]
# 0x00 0x14,pc/at bios boot from http,[Samer_El-Haj-Mahmoud]
# 0x00 0x15,arm 32 uboot,[Joseph_Shifflett]
# 0x00 0x16,arm 64 uboot,[Joseph_Shifflett]
# 0x00 0x17,arm uboot 32 boot from http,[Joseph_Shifflett]
# 0x00 0x18,arm uboot 64 boot from http,[Joseph_Shifflett]
# 0x00 0x19,RISC-V 32-bit UEFI,[Dong_Wei]
# 0x00 0x1a,RISC-V 32-bit UEFI boot from http,[Dong_Wei]
# 0x00 0x1b,RISC-V 64-bit UEFI,[Dong_Wei]
# 0x00 0x1c,RISC-V 64-bit UEFI boot from http,[Dong_Wei]
# 0x00 0x1d,RISC-V 128-bit UEFI,[Dong_Wei]
# 0x00 0x1e,RISC-V 128-bit UEFI boot from http,[Dong_Wei]
# 0x00 0x1f,s390 Basic,[Hendrik_Brueckner]
# 0x00 0x20,s390 Extended,[Hendrik_Brueckner]
# 0x00 0x21,MIPS 32-bit UEFI,[Jiading_Zhang]
# 0x00 0x22,MIPS 64-bit UEFI,[Jiading_Zhang]
# 0x00 0x23,Sunway 32-bit UEFI,[Jiading_Zhang]
# 0x00 0x24,Sunway 64-bit UEFI,[Jiading_Zhang]
# 0x00 0x25,LoongArch 32-bit UEFI,[LI_Chao][https://loongson.github.io/LoongArch-Documentation/README-EN.html][https://github.com/loongson/LoongArch-Documentation]
# 0x00 0x26,LoongArch 32-bit UEFI boot from http,[LI_Chao][https://loongson.github.io/LoongArch-Documentation/README-EN.html][https://github.com/loongson/LoongArch-Documentation]
# 0x00 0x27,LoongArch 64-bit UEFI,[LI_Chao][https://loongson.github.io/LoongArch-Documentation/README-EN.html][https://github.com/loongson/LoongArch-Documentation]
# 0x00 0x28,LoongArch 64-bit UEFI boot from http,[LI_Chao][https://loongson.github.io/LoongArch-Documentation/README-EN.html][https://github.com/loongson/LoongArch-Documentation]
# 0x00 0x29,arm rpiboot,[Peter_Harper][https://www.raspberrypi.com/documentation/computers/remote-access.html#network-booting-using-ipv6]
# 0x00 0x2a-0xff 0xff,Unassigned,



### sed 处理 每一行截取特定内容,并为每一行添加下一行, 添加的内容含有截取的特定内容;  思路:hold一份;处理一份;x交换;G追加下一行
sed -i '/.*/h; s/.* 0x\(.[a-z0-9]\),.*/if option pxe-system-typee = 00:\1 { \n\t#filename\n}/;x;G;' dhcpcode93配置.txt 



# 结果
cat dhcpcode93配置.txt

# Type,Architecture Name,Reference
# 0x00 0x00,x86 BIOS,[RFC5970][RFC4578]
if option pxe-system-type = 00:00 { 
	#filename
}
# 0x00 0x01,NEC/PC98 (DEPRECATED),[RFC5970][RFC4578]
if option pxe-system-type = 00:01 { 
	#filename
}
# 0x00 0x02,Itanium,[RFC5970][RFC4578]
if option pxe-system-type = 00:02 { 
	#filename
}
# 0x00 0x03,DEC Alpha (DEPRECATED),[RFC5970][RFC4578]
if option pxe-system-type = 00:03 { 
	#filename
}
# 0x00 0x04,Arc x86 (DEPRECATED),[RFC5970][RFC4578]
if option pxe-system-type = 00:04 { 
	#filename
}
# 0x00 0x05,Intel Lean Client (DEPRECATED),[RFC5970][RFC4578]
if option pxe-system-type = 00:05 { 
	#filename
}
# 0x00 0x06,x86 UEFI,[RFC5970][RFC4578]
if option pxe-system-type = 00:06 { 
	#filename
}
# 0x00 0x07,x64 UEFI,[RFC5970][RFC4578]
if option pxe-system-type = 00:07 { 
	#filename
}
# 0x00 0x08,EFI Xscale (DEPRECATED),[RFC5970][RFC4578]
if option pxe-system-type = 00:08 { 
	#filename
}
# 0x00 0x09,EBC,[RFC5970][RFC4578]
if option pxe-system-type = 00:09 { 
	#filename
}
# 0x00 0x0a,ARM 32-bit UEFI,[RFC5970]
if option pxe-system-type = 00:0a { 
	#filename
}
# 0x00 0x0b,ARM 64-bit UEFI,[RFC5970]
if option pxe-system-type = 00:0b { 
	#filename
}
# 0x00 0x0c,PowerPC Open Firmware,[Thomas_Huth]
if option pxe-system-type = 00:0c { 
	#filename
}
# 0x00 0x0d,PowerPC ePAPR,[Thomas_Huth]
if option pxe-system-type = 00:0d { 
	#filename
}
# 0x00 0x0e,POWER OPAL v3,[Jeremy_Kerr]
if option pxe-system-type = 00:0e { 
	#filename
}
# 0x00 0x0f,x86 uefi boot from http,[Samer_El-Haj-Mahmoud]
if option pxe-system-type = 00:0f { 
	#filename
}
# 0x00 0x10,x64 uefi boot from http,[Samer_El-Haj-Mahmoud]
if option pxe-system-type = 00:10 { 
	#filename
}
# 0x00 0x11,ebc boot from http,[Samer_El-Haj-Mahmoud]
if option pxe-system-type = 00:11 { 
	#filename
}
# 0x00 0x12,arm uefi 32 boot from http,[Samer_El-Haj-Mahmoud]
if option pxe-system-type = 00:12 { 
	#filename
}
# 0x00 0x13,arm uefi 64 boot from http,[Samer_El-Haj-Mahmoud]
if option pxe-system-type = 00:13 { 
	#filename
}
# 0x00 0x14,pc/at bios boot from http,[Samer_El-Haj-Mahmoud]
if option pxe-system-type = 00:14 { 
	#filename
}
# 0x00 0x15,arm 32 uboot,[Joseph_Shifflett]
if option pxe-system-type = 00:15 { 
	#filename
}
# 0x00 0x16,arm 64 uboot,[Joseph_Shifflett]
if option pxe-system-type = 00:16 { 
	#filename
}
# 0x00 0x17,arm uboot 32 boot from http,[Joseph_Shifflett]
if option pxe-system-type = 00:17 { 
	#filename
}
# 0x00 0x18,arm uboot 64 boot from http,[Joseph_Shifflett]
if option pxe-system-type = 00:18 { 
	#filename
}
# 0x00 0x19,RISC-V 32-bit UEFI,[Dong_Wei]
if option pxe-system-type = 00:19 { 
	#filename
}
# 0x00 0x1a,RISC-V 32-bit UEFI boot from http,[Dong_Wei]
if option pxe-system-type = 00:1a { 
	#filename
}
# 0x00 0x1b,RISC-V 64-bit UEFI,[Dong_Wei]
if option pxe-system-type = 00:1b { 
	#filename
}
# 0x00 0x1c,RISC-V 64-bit UEFI boot from http,[Dong_Wei]
if option pxe-system-type = 00:1c { 
	#filename
}
# 0x00 0x1d,RISC-V 128-bit UEFI,[Dong_Wei]
if option pxe-system-type = 00:1d { 
	#filename
}
# 0x00 0x1e,RISC-V 128-bit UEFI boot from http,[Dong_Wei]
if option pxe-system-type = 00:1e { 
	#filename
}
# 0x00 0x1f,s390 Basic,[Hendrik_Brueckner]
if option pxe-system-type = 00:1f { 
	#filename
}
# 0x00 0x20,s390 Extended,[Hendrik_Brueckner]
if option pxe-system-type = 00:20 { 
	#filename
}
# 0x00 0x21,MIPS 32-bit UEFI,[Jiading_Zhang]
if option pxe-system-type = 00:21 { 
	#filename
}
# 0x00 0x22,MIPS 64-bit UEFI,[Jiading_Zhang]
if option pxe-system-type = 00:22 { 
	#filename
}
# 0x00 0x23,Sunway 32-bit UEFI,[Jiading_Zhang]
if option pxe-system-type = 00:23 { 
	#filename
}
# 0x00 0x24,Sunway 64-bit UEFI,[Jiading_Zhang]
if option pxe-system-type = 00:24 { 
	#filename
}
# 0x00 0x25,LoongArch 32-bit UEFI,[LI_Chao][https://loongson.github.io/LoongArch-Documentation/README-EN.html][https://github.com/loongson/LoongArch-Documentation]
if option pxe-system-type = 00:25 { 
	#filename
}
# 0x00 0x26,LoongArch 32-bit UEFI boot from http,[LI_Chao][https://loongson.github.io/LoongArch-Documentation/README-EN.html][https://github.com/loongson/LoongArch-Documentation]
if option pxe-system-type = 00:26 { 
	#filename
}
# 0x00 0x27,LoongArch 64-bit UEFI,[LI_Chao][https://loongson.github.io/LoongArch-Documentation/README-EN.html][https://github.com/loongson/LoongArch-Documentation]
if option pxe-system-type = 00:27 { 
	#filename
}
# 0x00 0x28,LoongArch 64-bit UEFI boot from http,[LI_Chao][https://loongson.github.io/LoongArch-Documentation/README-EN.html][https://github.com/loongson/LoongArch-Documentation]
if option pxe-system-type = 00:28 { 
	#filename
}
# 0x00 0x29,arm rpiboot,[Peter_Harper][https://www.raspberrypi.com/documentation/computers/remote-access.html#network-booting-using-ipv6]
if option pxe-system-type = 00:29 { 
	#filename
}
# 0x00 0x2a-0xff 0xff,Unassigned,
if option pxe-system-type = 00:ff { 
	#filename
}


标签:字符,00,每行,option,0x00,system,filename,sed,pxe
From: https://www.cnblogs.com/huangjinbang1996/p/18617741

相关文章

  • 【C语言练习(12)—反向输出字符串】
    C语言练习(12)文章目录C语言练习(12)前言题目题目解析结果总结前言对于一个给定的字符串,反方向输出该字符串,本次给了循环和利用指针反向输出两种方法题目给定一个字符串,计算该字符串的个数并反向输出例如给定字符串ILoveStudy则反向输出后为ydutSevoLI题目解析......
  • 翻转字符串&翻转单词
    一、翻转字符串问题描述请实现⼀个算法,在不使⽤额外数据结构和储存空间的情况下,翻转⼀个给定的字符串(可以使⽤单个过程变量)。解题思路由于不允许使用额外的数据接口和存储空间,所以我们将⼀个字符串以中间字符为轴,前后翻转,也就是将str[len]赋值给str[0],将str[0]赋值str[len......
  • python的eval()函数的作用是将字符串转换成数值吗?
    不完全正确。Python的eval()函数的作用是将一个字符串作为Python表达式求值,并返回表达式的值。这意味着eval()可以处理各种数据类型和表达式,而不仅仅是将字符串转换成数值。例如:#将字符串转换为数值num_str="3+5"result=eval(num_str)print(result)#输出:8......
  • 华为OD E卷(100分)30-字符串变换最小字符串
    前言    工作了十几年,从普通的研发工程师一路成长为研发经理、研发总监。临近40岁,本想辞职后换一个相对稳定的工作环境一直干到老,没想到离职后三个多月了还没找到工作,愁肠百结。为了让自己有点事情做,也算提高一下自己的编程能力,无聊之余打算用一些大厂的编程题练练......
  • 【NLP 16、实践 ③ 找出特定字符在字符串中的位置】
    看着父亲苍老的白发和渐渐老态的面容希望时间再慢一些                                                ——24.12.19一、定义模型1.初始化模型①初始化父类super(TorchModel,self).__init__(): 调用父类nn.Mod......
  • R语言的字符串操作
    【图书推荐】《R语言医学数据分析实践》-CSDN博客《R语言医学数据分析实践李丹宋立桓蔡伟祺清华大学出版社9787302673484》【摘要书评试读】-京东图书(jd.com)R语言医学数据分析实践-R语言的数据结构-CSDN博客在R语言中,字符串是一种表示文本数据的数据类型。字符串......
  • Cmd that used a lot but always forget
    CmdthatusedalotbutalwaysforgetCompressoruncompress#compresstarcvzfcmprssd.tar.gzcmprssd/Tounpackorextractatarfile,type:tar-xvffile.tarREF:tar-extract-linuxTosavediskspaceandbandwidthoverthenetworkallfilesaresave......
  • 字符串合并与分割的正确方法是什么?
    在Python中,字符串的合并与分割操作可以通过split()和join()方法实现。以下是详细的说明:字符串分割(split)split()方法用于将字符串按照指定的分隔符分割成多个子字符串,并返回一个列表。如果不指定分隔符,默认使用空白字符(如空格、换行符、制表符等)进行分割。语法格式:str.split......
  • JS中把其它类型转成字符串的方法及规则是什么?
    在JavaScript中,有多种方法可以将其他类型转换为字符串。以下是一些常见的方法和规则:使用toString()方法:几乎所有的JavaScript对象都继承了toString()方法,该方法返回一个表示该对象的字符串。对于原始类型(如Number和Boolean),此方法会返回原始值的文本表示形式。对于数组和对象,默......
  • 只谈C++11新特性 - Range-based for 循环
    Range-basedfor循环引言C++11引入了一种更加简洁和直观的方式来遍历容器中的元素:基于范围的for循环(Range-basedfor循环)。这种语法不仅简化了代码,还提高了代码的可读性和维护性。本文将详细介绍Range-basedfor循环的用法,并结合代码示例进行说明。Range-based......