我正在自動執行一些任務。sed從另一個文件的內容逐行替換
我想知道是否有可能從不同的文件替換每一行中 導師將需要和源文件中的時間之間
每一行被構造爲
blahblahblah....string_I_need_to_replace....blahblahblah
我用sed命令解壓我需要更換,因爲它需要去從data1,data2,data3,
到data1-description; data2 - description; data3 - description
data1,data2,data3
並不總是個字符串Ë相同,僅data1
是保證在線路
此行
blahblah....mentor will be required.",Collaboration,Analytical Skills,Integrity & Ethics,3/1/17 20:04 ... blahblah
需求是
blahblah....mentor will be required.","Collaboration-description;Analytical Skills - description; Integrity & Ethics - description " 3/1/17 20:04 ....blah blah blah
在第一行我解析的文件包含
Collaboration-description;Analytical Skills - description; Integrity & Ethics - description
我已經使用sed命令來提取每行的內部部分Collaboration-description;Analytical Skills - description; Integrity & Ethics - description
在一個單獨的文件中。
有很多,
和;
和數字之前和之後我有興趣改變的數據和計數因行而異所以替換第n個,將是一個問題有多達三個,當data2和data3是空是原因outfile2
和outfile3
處理從而消除最後,
#!/bin/bash
unset LANG
cat export-14.csv | sed -n -e 's/^.*mentor will be required.",//p' > outfile
sed 's/[0-9].*//' outfile > outfile2
sed 's/,$//' outfile2 > outfile3
sed 's/,$//' outfile3 > outfile4
sed 's/,/;/g' outfile4 >outfile5
sed 's/Analytical SKills/Analytical Skills - identifying and solving problems/' outfile5 > outfile6
sed 's/Adaptability/Adaptability - embracing opportunities for improvement and resilience/' outfile6 > outfile7
sed 's/Collaboration/Collaboration - working with others/' outfile7 > outfile8
sed 's/Technology/Technology - employing current and emerging software\/tools/' outfile8 > outfile9
sed "s/Communication/Communication - articulating one\'s self/g" outfile9 > outfile10
我不確定我在這裏看到一個問題。也就是說,'sed -i -e'...'-e'...'-e'...''會表現更好。 – bishop
謝謝我的問題被埋沒了,很難看到我把真正的問題放在頂部附近「我想知道是否有可能用不同的文件替換每一行,導師將需要和源文件中的日期」 – brad
提出了一個醜陋的非靈活的解決方案,日期形式爲,年/月/年只發生一次每一行和導師將需要的數據之前,我需要改變,而不是做出單獨的文件我使用導師...和作爲標記的日期和替換內部的一切。工程,但醜陋 – brad