Last active
March 14, 2020 01:33
-
-
Save mdelillo/5c895793cb82797cdd76ce4ac459173f to your computer and use it in GitHub Desktop.
Insert multiple lines containing trailing slashes after a matching line in a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
cat >file.txt << 'EOF' | |
LINE 1 \ | |
LINE 2 \ | |
LINE 5 | |
EOF | |
set +e | |
IFS= read -r -d '' missing_lines << 'EOF' | |
LINE 3 \ | |
LINE 4 \ | |
EOF | |
set -e | |
awk -v lines="$missing_lines" -i inplace '{print} /LINE 2/{printf lines}' file.txt | |
# OUTPUT: | |
# LINE 1 \ | |
# LINE 2 \ | |
# LINE 3 \ | |
# LINE 4 \ | |
# LINE 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment