I have a text file with multiple datasets. I have written a code that searches for certain values (top left 4-letter code) in a text file but, now I need to be able to have the script copy out data from a set number of lines AFTER the match (“PHHI, etc”) is found. The data values are all formatted the
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
How to append entry the end of a multi-line entry using any of stream editors like sed or awk
I am trying to use a script to append the host name at the end of a multi-line entry of a specific Host_Alias field in sudoers file. The current sudoers file has an entry similar to : My required output would be something like the following where I have added “,host25” There are more lines before and after this segment.
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
Linux bash script removing part of string line by line
After greping output of command i have get below result: PAPU 0 1000 GPRS ATTACH SUCC GB 2400 2382 2333 (10) 1244 GPRS ATTACH FAIL GB 1216 1219 1252 (10) 16000 GPRS ATTACH SUCC IU 986 986 1027 (10) 16001 GPRS ATTACH FAIL IU 170 185 171 (10) 2000 PDP-C ACTIVATION SUCC GB 5356 5138 5030 (10) 2109 PDP-C ACTIVATION