Skip to content
Advertisement

Tag: sed

How to use sed to delete lines not containing pattern

I have a file as below: I need to delete all lines except the first line, which means that lines should not be deleted if it contains Thumb[any characters except /].jpg. I try to use sed to do this but I don’t know how to write the regex. I’ve tried like this: sed -i -e ‘.*Thumb^(/).jpg!d’ file but it doesn’t

Modify config files with sed in bash

I am trying to set net.ipv4.ip_forward to 1 in /etc/sysctl.conf.The following works fine but it sure missing some edge cases For e.g if the sysctl.conf contain any one of the following it won’t match #net.ipv4.ip_forward=1 ##net.ipv4.ip_forward=1. Is there a more reliable way to modify settings in config files ? Answer You can use the -r switch to enable Extended Regular

How to insert variable containing a path into sed

I’m writing a linux script, which is to replace a string for a file. Here is my script: In the file named test, there is a line like this: What I need is to replace this line with the line below: It means that things between double quotes should be replaced by the $var. However when I execute my script,

How to remove some string with awk/sed or another command in linux?

I want to ask, how I can remove some string with command in linux? and the output: Answer try: Making field separator as | then substituting the starting zeros with NULL of 111th field as per your requirements, mentioning 1 will print the newly edited line(if any zeros were replaced with NULL), setting Output field separator as | and mentioning

Sed: select first part of price

Seems that my sed command is not working. I am trying to select the 2 in $2.99. However, no matter how I seem to type the regex, it will only give the .99 I want to select everything (every number) that is not the dollar sign up to the period. Any suggestions? echo “$2.99” | sed -e ‘s:^([^\$]*).:the price is

Append input URL from user to variable in file using shell script

I have one file test.txt it have already some data named export website_URL and export username= test.txt start.sh here creating new file from test.txt writing data in to data.txt file here if I put input to website_URL=”http://stackoverflow.com/questions/6543841/php-cli-getting-input-from-user-and-then-dumping-into-variable-possible” it is failing with sed: -e expression #1, char 71: unknown option to `s’ this error . So I can store any url

sed/awk to replace in a loop

I have a file called “demo” that has names in our DNS. I’m trying to loop through each line and replace the “names” with “names and ip address” (as a way of verifying dns queries) So far I have this but no luck on sed or awk command. Help appreciated. Thanks. demo “diggs” has an alias that yields one line

Advertisement