当前位置: 技术问答>linux和unix
awk shell。匹配字符串
来源: 互联网 发布时间:2016-12-17
本文导语: 在一个文本中,一行的格式如下: (1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"),(1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"),(1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2...
在一个文本中,一行的格式如下:
(1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"),(1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"),(1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"),.....
现在想把上面每个括号里的数据单独形成一行,如下
1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"
1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"
....
请问如何处理。
ps 我初步用awk match函数。但是括号里的字符提取不出来
(1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"),(1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"),(1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"),.....
现在想把上面每个括号里的数据单独形成一行,如下
1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"
1,232,"dasdsa","种植","2011-01-01","2011-01-01,"2002-04-19 16:02:50","大多"
....
请问如何处理。
ps 我初步用awk match函数。但是括号里的字符提取不出来
|
你那括号是中文字符还是英文字符 你匹配的时候要输入一致!
然后用sed直接删除前括号(
用sed直接把后括号)替换成换行
然后用sed直接删除前括号(
用sed直接把后括号)替换成换行
|
你就先按我那个处理,去掉括号并换行
接着,你再用awk去处理:
cat 文件名 | awk 'BEGIN {FS=","} {printf "第1个字段:%s,第4个字段:%s",$1,$4}'
|
额,这里sed可能会比awk效果更好
|
听主席的准没错。呵呵
|
不修改原文件:
cat 原文件名| sed 's/(//g'| sed 's/)/n/g' > 新文件名
修改原文件:
sed -i 's/(//g' 文件名| sed -i 's/)/n/g' 文件名
已经过测试
cat 原文件名| sed 's/(//g'| sed 's/)/n/g' > 新文件名
修改原文件:
sed -i 's/(//g' 文件名| sed -i 's/)/n/g' 文件名
已经过测试
|
1. sed 's/((.[^)]*))[^(]*/1n/g'
2. awk 'BEGIN{RS=")";FS="("}NF>1{print $NF}'
3. grep -Po '(?
2. awk 'BEGIN{RS=")";FS="("}NF>1{print $NF}'
3. grep -Po '(?