Skip to content
Advertisement

Tag: sed

Partially replace string using ‘sed’ shell command

I need to delete the <#> in the following pattern: Outputs should be like: I was trying to do this sed ‘s/(vdd1[a-z]*).<[0-9]>/1/’ file1 > file2 But it gives me “vdd1” all the way. How can I do it correctly? Answer The dot . after the paren is matching the letter after the 1. You need to get rid of it.

compare the length of multiple files using awk or sed

I want to compare the number of lines of each file and choose the one that contains the maximum number of lines for example I will get as result Answer Alternative with lot’s of piping this script assumes the file names are under your control and space or _V won’t appear in the base names. Otherwise check out @Qualia’s version.

SED one liner to uncomment and replace first occurrence of a pattern

I have this settings.conf file in linux defined as follows: I would like to uncomment # second-setting = off of Section A only (first occurrence), and set the value to on. So far, I have this: cat settings.conf | sed ‘/^# second.*/ {s/^#//;s/off/on/}’ Any tips? Answer Is this what you had in mind? Or if your on osx with non-gnu

Extract substring from string in linux

i need to extract oracle-xe-11.2.0-1.0.x86_64.rpm from oracle-xe-11.2.0-1.0.x86_64.rpm.zip and i have no clue how to start. The condition that must be met is only .zip needs to be removed. If there is no .zip then nothing should happen to the string . How to go with it ? Answer Use basename instead: Result:

grep the filename using sed

I have the following line I would like to get and change just the (result_0.01) part to a different text which might include numbers. Preferably I would like this to be done using sed. Thank you in advance. Answer what happens here in sed part is: we substitude (s flag at the beginning of sed) we find everything till .dat.

SED not working [unterminated `s’ command]

i am trying to replace content of file using sed by following commands but it is giving Answer You’re missing a separator (which is ~ in your case). It looks like you are trying to put it on the end of $searchString, which is strange. I don’t know why you’re doing that. The reason it doesn’t work is because the

Replace a line with a number if part of it is matches using sed

I know this is a very simple question and been discussed many times, but I can’t understand where I am doing wrong in my command. I would like to replace the lines which starts with “It” as 99999. Each row starts with several blank spaces. I used But it is not working. Answer give this a try:

How to grep a particular pattern

I am trying to get a particular pattern, but i get the result for all possible solutions I did try all the solutions available here How do I get only the PID: 467? Answer If your goal is to grep only for “lubuntu”, not “lubuntu-somethingelse”, then you can add a space afterwards: Or without the extra commands: Edit: If you

Advertisement