Skip to content
Advertisement

Tag: sed

Unix – Uncomment xml comments

I have below node from XML file. How do I uncomment the first occurrance of mainHost using Unix shell script or commands? I have tried with below command with different variations but that does not seem to work. sed ‘0,/<!– /{s/<!– //}’ /test.xml I am expecting below output Thanks Answer You were on the right track (under the assumption that

How to stop newline chars from escaping OLD gnu sed command

I am trying to replace a line in a file with multiple lines. When I had only one new line char ( ‘$’n ). it worked fine, however when I use two of them, it escapes my sed and the file wont run anymore. File.txt: DesiredOutput Actual Output Answer Using older BSD sed you can do: This should work with

Expanding shell variable in sed in remote host

The sed command, which is run locally looks like this (it works fine): However, if i try t run the same in a remote host doing an ssh, it gives me issue: What am i missing here? Answer Variable Expansion The problem you’re encountering has to do with shell expansion in strings. There are two relevant categories of strings: singly-quoted

sed with variable as argument in bash script

I am trying to write a bash script to scan for authorized_keys files and remove the keys of a couple previous employees if found. I am having one heck of a time figuring out the escaping for the sed command at the end. I am using commas instead of / since / can show up in the ssh-key. Any help

How cut characters from string and put it at the end- In shell

I want to be able to do the following: And get output like: I know the command sed is able to do this but I need some guidance. Thanks! Answer In sed you can do: Which outputs 3002_3322 3.2.1.log HELLO. Explanation The first word is captured by ([^[:blank:]]*) The () means I want to capture this group to use later.

How can I fix the following sed command?

I am trying to append _out to anything that matches the regex shown in the follwing sed command. The _out should be before the [ (]. The command returns the lines correctly as I expect. Now the problem comes when I try the following command where I define regions to use in the replacement. So for example if I have

Replace characters in specific columns only (CSV)

I have data like this: It has dot . as decimal separator but I need to use , instead. Desired data: I tried using Sed. With sed -i ‘s/./,/g’ myfile.csv I could replace all dots with commas but would destroy dates on the fourth column. How can I change dots to commas in elsewhere but leave the fourth column as

Advertisement