Skip to content

Instantly share code, notes, and snippets.

@paul-schwendenman
Created September 9, 2016 00:38
Show Gist options
  • Save paul-schwendenman/9f5edb5b978f0800d65a07e1236fe01a to your computer and use it in GitHub Desktop.
Save paul-schwendenman/9f5edb5b978f0800d65a07e1236fe01a to your computer and use it in GitHub Desktop.
Sed Replace package.json

Directory structure:

$ tree
.
├── a
│   ├── a
│   │   ├── other.json
│   │   └── package.json
│   ├── other.json
│   └── package.json
├── b
│   ├── other.json
│   └── package.json
└── c
    ├── other.json
    └── package.json

4 directories, 8 files

File contents before:

$ find . -name package.json -type f -print -exec cat {}  \;
./a/a/package.json
{
"this": "0.3.1"
}
./a/package.json
{
"this": "0.3.1"
}
./b/package.json
{
"this": "0.3.1"
}
./c/package.json
{
"this": "0.3.1"
}

Replace the version:

$ find . -name package.json -type f -maxdepth 2 -print -exec sed -i '' -e 's/"this": "0.3.1"/"this": "0.4.0"/' {}  \;
./a/package.json
./b/package.json
./c/package.json

Contents after:

$ find . -name package.json -type f -print -exec cat {}  \;
./a/a/package.json
{
"this": "0.3.1"
}
./a/package.json
{
"this": "0.4.0"
}
./b/package.json
{
"this": "0.4.0"
}
./c/package.json
{
"this": "0.4.0"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment