(\^|\~?)(\d|x|\*)+\.(\d|x|\*)+\.(\d|x|\*)+
패턴을 행운없이 sed
과 대조하려고합니다. 내가 통해 실행하고있어 파일은 이것이다 :sed와 정규 표현식을 일치시킬 수 없습니다
{
"name": "something",
"version": "0.0.1",
"description": "some desc",
"main": "gulpfile.js",
"directories": {
"test": "tests"
},
"dependencies": {
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"gulp-clean": "^0.3.2",
"jquery": "^2.1.4",
"lodash": "^4.0.0",
"moment": "^2.13.0",
"moment-timezone": "^0.5.0",
"radium": "^0.16.2",
"react": "^15.1.0",
"react-bootstrap-sweetalert": "^1.1.10",
"react-dom": "^15.1.0",
"react-timeago": "^2.2.1",
"sprintf": "^0.1.5",
"smoothscroll": "~0.2.2"
},
"devDependencies": {
"babel": "^6.3.26",
"babelify": "^7.2.0",
"browserify": "~12.0.1",
"console-stamp": "^0.2.0",
"estraverse-fb": "^1.3.1",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-sass": "^2.1.1",
"gulp-sourcemaps": "^1.6.0",
"gulp-util": "^3.0.7",
"lodash": "4.5.1",
"lodash.assign": "^3.2.0",
"lodash.isfunction": "^3.0.8",
"lodash.reduce": "^4.3.0",
"node-sass": "3.4.2",
"react-bootstrap": "^0.29.4",
"react-intl": "2.1.0",
"reactify": "1.1.1",
"sweetalert": "^1.1.3",
"vinyl": "^1.1.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.4.0",
"jsx-to-string": "~0.2.11"
},
"optionalDependencies": {
"pkg-save": "~1.0.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "someurl"
},
"author": "authorname",
"license": "MIT"
}
가 원하는 패턴과 일치 regexr 당신은에서 볼 수있다 (또한 "버전"일치를하지만 나중에 해결할 수 있습니다 또 다른 문제이다)로서 : http://regexr.com/3e324
나는 다음과 같은 명령으로 나오지 호출 호출하고있어: 간결성을 위해
cat package.json | sed 's/(\^|\~?)(\d|x|\*)+\.(\d|x|\*)+\.(\d|x|\*)+/Hello/g' -r
, 그것은 같은 출력 (즉 필터링되지 않은 입력.) :
...
"dependencies": {
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"gulp-clean": "^0.3.2",
...
"모든 숫자를"Hello "로 대체해야합니다.
내가 뭘 잘못하고 있니?
뭔가 나쁜 플래그 (내가 시도했습니다 /gm
)
올바른 정규식 엔진을 사용하지 않고 (내가 확장 정규식을 활용하는 -r
옵션을 전달 해요)?
당신의'sed' 문제 (미안)에 대한 답을 모르겠다. 그러나 나는 당신이 이것과 같은 JSON 작업을한다면 [jq]와 같이 더 적합한 도구를 사용하고 싶을지도 모른다. (https://stedolan.github.io/jq/) – Matt
감사합니다. 이것이 내가 필요한 것일 수도 있습니다! package.json 파일을 직접 조작 할 수있는 도구가 필요하며 변경 대상을 완전히 제어 할 수있는 곳이 필요합니다. –
'\ d'보다는'[0-9]'를 사용하여 해결했습니다. (나는 여전히 JSON을 많이 처리 할 때'jq'를 사용하여 두 번째로) – Aaron