使用Grep Sed或Awk搜索和替换EDL文件中的行

时间:2014-07-04 03:27:47

标签: regex search awk sed grep

基本上,我尝试使用sed,grep或awk来解决这个问题:

001  AX       V     C        00:00:32:09 00:00:40:19 00:00:00:00 00:00:08:10
* FROM CLIP NAME: 001_M04-1008rev.mov

002  AX       V     C        00:00:20:04 00:00:30:11 00:00:08:10 00:00:18:17
* FROM CLIP NAME: 001_M04-1011rev.mov

003  AX       V     C        00:00:15:00 00:00:26:05 00:00:18:17 00:00:29:22
* FROM CLIP NAME: 001_M04-1012rev.mov

004  AX       V     C        00:00:20:01 00:00:30:13 00:00:29:22 00:00:40:10
* FROM CLIP NAME: 001_M04-1027rev.mov

005  AX       V     C        00:00:24:22 00:00:30:09 00:00:40:10 00:00:45:21
* FROM CLIP NAME: 001_M04-1028rev.mov

006  AX       V     C        00:00:38:04 00:00:49:03 00:00:45:21 00:00:56:20
* FROM CLIP NAME: 001_M04-1029rev.mov

对此:

001  1008rev       V     C        00:00:32:09 00:00:40:19 00:00:00:00 00:00:08:10
* FROM CLIP NAME: 001_M04-1008rev.mov

002  1011rev       V     C        00:00:20:04 00:00:30:11 00:00:08:10 00:00:18:17
* FROM CLIP NAME: 001_M04-1011rev.mov

003  1012rev       V     C        00:00:15:00 00:00:26:05 00:00:18:17 00:00:29:22
* FROM CLIP NAME: 001_M04-1012rev.mov

004  1027rev       V     C        00:00:20:01 00:00:30:13 00:00:29:22 00:00:40:10
* FROM CLIP NAME: 001_M04-1027rev.mov

005  1028rev       V     C        00:00:24:22 00:00:30:09 00:00:40:10 00:00:45:21
* FROM CLIP NAME: 001_M04-1028rev.mov

006  1029rev       V     C        00:00:38:04 00:00:49:03 00:00:45:21 00:00:56:20
* FROM CLIP NAME: 001_M04-1029rev.mov

有什么建议吗?基本上我在#34; .mov"之前拍摄了最后7个字符。并移动这些字符代替" AX"它位于前一行之前。

2 个答案:

答案 0 :(得分:2)

这是使用awk的一种方式:

awk '{ sub($2, substr($NF, length($NF) - 10, 7)) }1' RS= ORS="\n\n" file

这是使用perl的一种方式:

perl -00 -pae 's/$F[1]/substr($F[-1], -11, 7)/e' file

请注意,AWK解决方案将为您提供尾随换行符,而Perl解决方案则不会。这个甚至是否相关是另一回事。

答案 1 :(得分:0)

这是一个潜在的awk解决方案:

awk 'BEGIN { buf=""; } /AX/ { buf=$0; } /.mov$/ { match($0, /\-([^\-\.]+).mov/, n); gsub("AX", n[1], buf); print buf,"\n",$0,"\n"; }' < test.txt

其中输出以下内容:

001  1008rev       V     C        00:00:32:09 00:00:40:19 00:00:00:00 00:00:08:10
 * FROM CLIP NAME: 001_M04-1008rev.mov

002  1011rev       V     C        00:00:20:04 00:00:30:11 00:00:08:10 00:00:18:17
 * FROM CLIP NAME: 001_M04-1011rev.mov

003  1012rev       V     C        00:00:15:00 00:00:26:05 00:00:18:17 00:00:29:22
 * FROM CLIP NAME: 001_M04-1012rev.mov

004  1027rev       V     C        00:00:20:01 00:00:30:13 00:00:29:22 00:00:40:10
 * FROM CLIP NAME: 001_M04-1027rev.mov

005  1028rev       V     C        00:00:24:22 00:00:30:09 00:00:40:10 00:00:45:21
 * FROM CLIP NAME: 001_M04-1028rev.mov

006  1029rev       V     C        00:00:38:04 00:00:49:03 00:00:45:21 00:00:56:20
 * FROM CLIP NAME: 001_M04-1029rev.mov