Last active
October 10, 2022 15:02
-
-
Save shaisachs/dea6f63bd77e1288504f98a72bb47361 to your computer and use it in GitHub Desktop.
Adding and swapping lines in sed
This file contains 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
# I had a bunch of files across three different directories | |
# I wanted to combine them into one big directory with a "format" marker to indicate what type of file they were | |
# Here's how I did it in sed | |
mkdir tmp | |
cp gitrepos/* tmp/ | |
cd tmp | |
for f in *.md ; do sed -i '' '3 i\ | |
format: gitrepo | |
' $f ; done | |
for f in *.md ; do sed -i '' 's/repourl/url/g' $f ; done | |
# avoid name collisions | |
for f in *.md ; do mv $f `echo $f | sed 's/.md//g'`-gitrepos.md ; done | |
mv tmp/* dest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment