Skip to content

Instantly share code, notes, and snippets.

@shaisachs
Last active October 10, 2022 15:02
Show Gist options
  • Save shaisachs/dea6f63bd77e1288504f98a72bb47361 to your computer and use it in GitHub Desktop.
Save shaisachs/dea6f63bd77e1288504f98a72bb47361 to your computer and use it in GitHub Desktop.
Adding and swapping lines in sed
# 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