Created
November 16, 2025 07:37
-
-
Save saiqulhaq/3eba42abb7276ed4934abde0b2c53931 to your computer and use it in GitHub Desktop.
remove archived
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
| #!/bin/bash | |
| # Script to remove "- archived -" lines and their nested children | |
| # Usage: ./remove_archived.sh input.txt | |
| awk ' | |
| BEGIN { | |
| skip = 0 | |
| skip_indent = -1 | |
| } | |
| { | |
| # Count leading whitespace (tabs/spaces) | |
| match($0, /^[[:space:]]*/) | |
| current_indent = RLENGTH | |
| # Check if line starts with "- archived -" (after whitespace) | |
| if ($0 ~ /^[[:space:]]*- archived -/) { | |
| skip = 1 | |
| skip_indent = current_indent | |
| next | |
| } | |
| # If we are skipping and current line has greater indentation, skip it | |
| if (skip == 1 && current_indent > skip_indent) { | |
| next | |
| } | |
| # If we reach a line with equal or less indentation, stop skipping | |
| if (skip == 1 && current_indent <= skip_indent) { | |
| skip = 0 | |
| skip_indent = -1 | |
| } | |
| # Print the line if not skipping | |
| if (skip == 0) { | |
| print $0 | |
| } | |
| } | |
| ' "${1:-/dev/stdin}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment