2017-05-25 154 views
1

我有一個名爲sso_med.txt與AWK查找和替換

 insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('502683504',16,current_date, '502264160', current_date, '502264160'); 
     insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('502689031',15,current_date, '502264160', current_date, '502264160'); 
     insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('502689031',16,current_date, '502264160', current_date, '502264160'); 
     insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('212462117', 15, current_date, '502264160', current_date, '502264160'); 
     insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('212462117', 16, current_date, '502264160', current_date, '502264160'); 

我想'502689031',16,current_date,

之間引入一個空間的文件所以,我想下面的命令

awk '{gsub(/,[0-9a-zA-Z]/, ", "); print}' sso_med.txt 

但我我沒有得到我期待的東西

insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('502683504', 6, urrent_date, '502264160', current_date, '502264160'); 
insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('502689031', 5, urrent_date, '502264160', current_date, '502264160'); 
insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('502689031', 6, urrent_date, '502264160', current_date, '502264160'); 
+0

其從CURRENT_DATE切出「c」和從數字「1」,並與空間 – sromit

回答

2

AWK溶液:

awk '{ gsub(/, */, ", ", $0) }1' sso_med.txt 

輸出:

insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('502683504', 16, current_date, '502264160', current_date, '502264160'); 
insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('502689031', 15, current_date, '502264160', current_date, '502264160'); 
insert into brs.user_components (user_name, component_id, created_date, created_by, last_updated_date, last_updated_by) values ('502689031', 16, current_date, '502264160', current_date, '502264160'); 

  • gsub(/, */, ", ", $0) - 替換/ 重新排列每個分離器(即,)與單一尾部空格
0

只要給後面參考:

awk '{gsub(/,[0-9a-zA-Z]/, " &"); print}' sso_med.txt 
+0

替換它們它引入了一個額外, – sromit

+0

@sromit好的,不用逗號試試 - 看更新 –