Skip to content

Instantly share code, notes, and snippets.

@sursir
Last active June 19, 2019 11:55
Show Gist options
  • Save sursir/d88ba1d9f6db4cf0615b9fe9d1561e52 to your computer and use it in GitHub Desktop.
Save sursir/d88ba1d9f6db4cf0615b9fe9d1561e52 to your computer and use it in GitHub Desktop.
ansible replace & add some word char & unique remove duplicate lines
# https://www.php.net/manual/zh/regexp.reference.assertions.php
# https://www.linuxquestions.org/questions/programming-9/ansible-how-to-remove-duplicate-lines-4175654440/
# 补一些缺失的词
ansible busserv --become -m replace -a '
path=/var/spool/cron/root
regexp="CmdLog/(?!new/)"
replace="CmdLog/new/"
'
# 文件备份
ansible busserv --become -m copy -a '
src=/var/spool/cron/root
dest=/tmp/root_cron_backup_3
remote_src=yes
'
# 文件内对行去重
# awk '!a[$0]++' source > uniqued_a2 | \cp -f uniqued_a2 source
ansible busserv --become -m shell -a '
awk '\''!a[$0]++'\'' /var/spool/cron/root > /tmp/root_cron_uniq_3 | \cp -f /tmp/root_cron_uniq_3 /var/spool/cron/root
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment