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
Tag: sed
Use awk to match a word, then find the first occurrence of another word
I am trying to find a way to re-search for another matching word after I already had a match. I am specifically trying to get the brightness value of one of my monitors. For example a part of the output of my xrandr –verbose is the following: I want to look for the word connected and then get the first
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
How do I grep or sed in a continuous stream of characters?
I have a program that output some text and then a continuous stream of characters: I want to exit this program as soon as “A” is seen in the output and I tried: However, it seems like grep doesn’t see the “A”s until the perl program exits. I also tried with sed with no luck; Any ideas how I can
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
Linux: Append variable to end of line using line number as variable
I am new to shell scripting. I am using ksh. I have this particular line in my script which I use to append text in a variable q to the end of a particular line given by the variable a containing the line number . Now the variable q can contain a large amount of text, with all sorts of
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