![](/img/trans.png)
[英]How to copy the first few lines of a giant file, and add a line of text at the end of it using some Linux commands?
[英]To add string at the end of matched line with directory structure using linux commands
我需要在使用 linux 命令匹配字符串的文件末尾添加值。 問題是我們在文件末尾添加的字符串包含目錄結構,而 sed 實用程序無法處理。
示例文件:
192.168.2.3 domain.com
192.168.2.3 domain2.com
預期產出
將 value[/home/user/directory] 添加到匹配的字符串 [192.168.2.3]
192.168.2.3 domain.com
192.168.2.3 domain2.com /home/user/directory
單程:
awk -v home="$HOME" '/192\.168\.2\.3/{$0= $0 FS home}1' file
如果該行包含 IP 模式,則將主目錄附加到當前行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.