给定一个带有多行的.txt
文档,如何提取该行的一部分并将该提取的位附加到行的前面,我从中提取它?
示例:
sometext("txt_to_be_ext", some_more_text)
分为:
"txt_to_be_ext",sometext("txt_to_be_ext", some_more_text)
答案 0 :(得分:1)
使用gawk
' match
功能:
awk '{match($0,/.*("[^"]+").*/,a);$0=a[1]"," $0}1' input_file
"txt_to_be_ext",sometext("txt_to_be_ext", some_more_text)
答案 1 :(得分:1)
sed 's/sometext.*(\(".*"\).*/\1,&/' input_file
简要说明,
"txt_to_be_ext"
,其中\1
将引用相应的匹配。&
会引用sometext.*(\(".*"\).*