BSD sed: extra characters at the end of d command

For anyone who found this question due to a similar error message, but caused by an attempt to in-place edit on Mac OS X As per https://github.com/lmquang/til/issues/18: OS X requires the extension to be explicitly specified. The workaround is to set an empty string: $ sed -i ” ‘s/megatron/pony/g’ /path/to/file.txt ^^ man sed: -i extension … Read more

How to replace a value with the output of a command in a text file?

In general, do use this syntax: sed “s/<expression>/$(command)/” file This will look for <expression> and replace it with the output of command. For your specific problem, you can use the following: sed “s/0/$(date +%s)/g” input.txt > output.txt This replaces any 0 present in the file with the output of the command date +%s. Note you … Read more

Delete using a different delimiter with Sed

The delimiters // that you’re using are not for the d command, they’re for the addressing. I think you’re comparing them to the slashes in the s/// command… However although both relate to regular expressions, they are different contexts. The address (which appears before the command) filters which lines the command is applied to… The … Read more

Using sed to replace beginning of line when match found

Capture the whole line that contains myvar: $ sed ‘s/\(^.*myvar.*$\)/\/\/\1/’ file $ cat hw.java class hw { public static void main(String[] args) { System.out.println(“Hello World!”); myvar=1 } } $ sed ‘s/\(^.*myvar.*$\)/\/\/\1/’ hw.java class hw { public static void main(String[] args) { System.out.println(“Hello World!”); // myvar=1 } } Use the -i option to save the changes … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)