当前位置: 技术问答>linux和unix
shell如何实现这种高难度的合成
来源: 互联网 发布时间:2015-09-09
本文导语: shell如何实现这种高难度的合成 文件如下: [2005/02/18 13:44:23 B0099S05] SELECT a, || b, || from dual; [2005/02/18 13:44:23 B0099S05] UPDATE MATERIAL T || SET T.CDELDATE = '20050216' [2005/02/18 13:44:23 B0099S05] DELETE * from MATERIAL; aaaa...
shell如何实现这种高难度的合成
文件如下:
[2005/02/18 13:44:23 B0099S05] SELECT a,
|| b,
|| from dual;
[2005/02/18 13:44:23 B0099S05] UPDATE MATERIAL T
|| SET T.CDELDATE = '20050216'
[2005/02/18 13:44:23 B0099S05] DELETE * from MATERIAL;
aaaaaaaaaaa
bbbbbbbbbb
PL/SQL over!。
要求:
1:将文件中所有含有B0099S05的行,的下一行含有||的去掉||合成一行,生成另一个
文件; 即新文件应该如下:
[2005/02/18 13:44:23 B0099S05] SELECT a, b, from dual;
[2005/02/18 13:44:23 B0099S05] UPDATE MATERIAL T SET T.CDELDATE = '20050216'
[2005/02/18 13:44:23 B0099S05] DELETE * from MATERIAL;
请教大虾阿:
谢谢!
文件如下:
[2005/02/18 13:44:23 B0099S05] SELECT a,
|| b,
|| from dual;
[2005/02/18 13:44:23 B0099S05] UPDATE MATERIAL T
|| SET T.CDELDATE = '20050216'
[2005/02/18 13:44:23 B0099S05] DELETE * from MATERIAL;
aaaaaaaaaaa
bbbbbbbbbb
PL/SQL over!。
要求:
1:将文件中所有含有B0099S05的行,的下一行含有||的去掉||合成一行,生成另一个
文件; 即新文件应该如下:
[2005/02/18 13:44:23 B0099S05] SELECT a, b, from dual;
[2005/02/18 13:44:23 B0099S05] UPDATE MATERIAL T SET T.CDELDATE = '20050216'
[2005/02/18 13:44:23 B0099S05] DELETE * from MATERIAL;
请教大虾阿:
谢谢!
|
# cat file | sed -e :a -e '$!N;s/n||/ /;ta' -e 'P;D'
|
试试看,这个perl版的中不?
-------------------------
#!/usr/bin/perl
$src = $ARGV[0];
$dest = $ARGV[1];
open IN,$src;
open OUT,">$dest";
while() {
s/(r)?n$//;
s/^||//;
s/^[/n/; # Linux version
print OUT $_;
}
close OUT;
close IN;
-------------------------
思路:
1.去回车 2. 去 "||" 3. 加回车
用法:
另存为 conv.pl
$ perl conv.pl yourOrgFile yourOutputFile
最近比较闲,呵呵 ...
-------------------------
#!/usr/bin/perl
$src = $ARGV[0];
$dest = $ARGV[1];
open IN,$src;
open OUT,">$dest";
while() {
s/(r)?n$//;
s/^||//;
s/^[/n/; # Linux version
print OUT $_;
}
close OUT;
close IN;
-------------------------
思路:
1.去回车 2. 去 "||" 3. 加回车
用法:
另存为 conv.pl
$ perl conv.pl yourOrgFile yourOutputFile
最近比较闲,呵呵 ...
|
相同的做法,
用shell 的sed也应该能做出来。
可,那个俺不会。
用shell 的sed也应该能做出来。
可,那个俺不会。
|
有sed2perl or awk2perl,不知道有没有perl2awk 或是 perl2sed
|
写了个shell脚本.
#!/bin/sh
# runsql.sh
sed '/^[^[||]/d' rec.txt >out1.txt
while read LINE
do
case $LINE in
[*) echo -n "$LINE" >>out2.txt
;;
|*) echo -n "$LINE" >>out2.txt
;;
esac
done out.txt
rm -f out1.txt out2.txt
#!/bin/sh
# runsql.sh
sed '/^[^[||]/d' rec.txt >out1.txt
while read LINE
do
case $LINE in
[*) echo -n "$LINE" >>out2.txt
;;
|*) echo -n "$LINE" >>out2.txt
;;
esac
done out.txt
rm -f out1.txt out2.txt