提取cpio.gz里面用命令创建

问题描述:

我有cpio.gz两档: cat a.cpio.gz b.cpio.gz > c.cpio.gz提取cpio.gz里面用命令创建

现在我想提取此c.cpio.gz文件b.cpio.gz和a.cpio 。广州。我怎样才能达到目的?

+0

好吧,阅读[this](http://stackoverflow.com/questions/13112604/find-gzip-start-and-end)并在'c中查找'b.cpio.gz'的开始标记。 cpio.gz“,并在该标记之前和之后提取文件,排除并包括需要的地方。下次使用'tar'。 –

+0

嗯,我必须使用cpio.gz由于要求。 – bercik

好的,我有2 .gz文件,a.txt.gzb.txt.gz。然后:

$ cat a.txt.gz b.txt.gz > c.txt.gz 
$ hexdump -C c.txt.gz 
00000000 1f 8b 08 08 f7 a3 00 59 00 03 61 2e 74 78 74 00 |.......Y..a.txt.| 
00000010 4b 2c 4e e1 4a 24 80 01 a9 66 ae 58 24 00 00 00 |K,N.J$...f.X$...| 
00000020 1f 8b 08 08 01 a4 00 59 00 03 62 2e 74 78 74 00 |.......Y..b.txt.| 
00000030 2b 2c 4f e5 2a 24 0a 73 a5 72 01 00 70 24 d5 0a |+,O.*$.s.r..p$..| 
00000040 2d 00 00 00          |-...| 

看到那些1f 8b 08从0x00开始和0x20的,他们是.gz文件(based on the article I referred to in the OP's comments)的BOF标志。现在一些AWK:

$ awk ' 
BEGIN { RS="\x1f\x8b\x08"; ORS="" } # set the marker to RS 
NR==2 { print RS $0 > "a2.txt.gz" } # output the marker and what's after first marker 
NR==3 { print RS $0 > "b2.txt.gz" } # output the marker and what's after the second 
' c.txt.gz 

可生产2个文件,并根据我的diff他们是相同的原始文件。