Thanks to visit codestin.com
Credit goes to github.com

Skip to content

using sed to replace just the first occurrence of a string #813

@steophy

Description

@steophy

Hello there

Node version (or tell us if you're using electron or some other framework):

v7.10.0

ShellJS version (the most recent version/Github branch you see the bug on):

v0.8.0

Operating system:

MacOs HighSierra 10.13.2

Description of the bug:

I'm using shelljs to perform a sed command and replace the whole line with a certain occurrence with another text. Here's the code that I'm using:


require('shelljs/global');

var new_version = process.argv[2];

sed('-i', /^.*version.*$/,
    '  "version": "'+new_version+'",',
    'package.json');

That version works but it replaces all the occurrence of "version". I have tried this code to replace only the first occurrence:

sed('-i', '0,/^.*version.*$/',

but that's not working at all: the file remains unchanged.

What am I missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion from a user (which may not require code/documentation changes to the project)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions