I want to replace create_test in the file with #create_test if the next line contains psfxxx_16_pi. How can I do it with sed for the whole file containing this?  Input file content:  create_test -type hard -outer { 1.0000 } { \     psfxxx_16_pi/psfop/deadline_north_re_0 }  create_test -type hard -outer { 0.0000 } { \     psfxxx_16_pi/psfop/deadline_south_re_1 }   Output file:  #create_test -type hard -outer { 1.0000 } { \     psfxxx_16_pi/psfop/deadline_north_re_0 }  #create_test -type hard -outer { 0.0000 } { \     psfxxx_16_pi/psfop/deadline_south_re_1 }
123314
I have one file like:  ID_SOUR_CALENDAR BIGINT NOT NULL DEFAULT 0  COMPRESS 0 , UNIQUE PRIMARY INDEX ( CALENDAR_DATE ); ID , ID_SOUR , PRIMARY INDEX ( CALENDAR_DATE );   I want to replace the ',' by ')' in the line just before the line containing PRIMARY.  The result should be:  ID_SOUR_CALENDAR BIGINT NOT NULL DEFAULT 0  COMPRESS 0 ) UNIQUE PRIMARY INDEX ( CALENDAR_DATE ); ID , ID_SOUR ) PRIMARY INDEX ( CALENDAR_DATE );
104690
I want to sed using a variable.  For example, sed -n '1,10p' file. So, instead of 10, I want to use $k where k is an integer.
53214
I am attempting to write a filter using something like sed or awk to do the following:   If a given pattern does not exist in the input, copy the entire input to the output If the pattern exists in the input, copy only the lines after the first occurrence to the output   This happens to be for a "git clean" filter, but that's probably not important. The important aspect is this needs to be implemented as a filter, because the input is provided on stdin.  I know how to use sed to delete lines up to a pattern, eg. 1,/pattern/d but that deletes the entire input if /pattern/ is not matched anywhere.  I can imagine writing a whole shell script that creates a temporary file, does a grep -q or something, and then decides how to process the input. I'd prefer to do this without messing around creating a temporary file, if possible. This needs to be efficient because git might call it frequently.
14743
To all the 'sed' doctors out there:  How can you get 'sed' to extract a regular expression it has matched in a  line?   In other words words, I want just the string corresponding to the regular  expression with all the non-matching characters from the containing line stripped away.  I tried using the back-reference feature like below  regular expression to be isolated           gets `inserted`                here                     |                v    sed -n 's/.*\( \).*/\1/p    this works for some expressions like   sed -n 's/.*\(CONFIG_[a-zA-Z0-9_]*\).*/\1/p    which neatly extracts all macro names starting with 'CONFIG_ ....' ( found in some '*.h' file ) and prints them all out line by line             CONFIG_AT91_GPIO           CONFIG_DRIVER_AT91EMAC                    .                    .              CONFIG_USB_ATMEL           CONFIG_USB_OHCI_NEW                    .                  e.t.c.    BUT the above breaks down for something like    sed -n 's/.*\([0-9][0-9]*\).*/\1/p    this always returns single digits like                    7                  9                  .                  .                    6   rather than extracting a contiguous number field such as.                 8908078               89670890                    .                  .                    .                23019                     .                e.t.c.     P.S.: I would be grateful to feedback on how this is achieved in 'sed'.        I know how to do this with 'grep' and 'awk'       I would like to find out if my - albeit limited - understanding of        'sed' has holes in it and if there is way to do this in 'sed' which I       have simply overlooked.
50199
I'm a relative Linux novice.  Suppose that I have a text file a.txt that contains the following text:  A B C   Now, if I want to change the text on line 2 (which contains B), I can use the following sed command:  sed -i '2s/^.*$/X/' a.txt   to change the B to X, for example.  But now suppose that I want to write an sed command that changes the text on line 2 to something that includes a bash string variable.  I want to change the text on line 2 to fname="myaddress", where the quotation marks are included explicitly, and where myaddress is a bash string variable (defined somewhere else).  To try to do this, I have created a bash shell script called mytest.sh and containing the following:  #!/bin/bash  myaddress="/home/" echo fname=\"$myaddress\"  head a.txt sed -i '2s/^.*$/fname=\"$myaddress\"/' a.txt head a.txt   Now, echo fname=\"$myaddress\" prints fname="/home/", which is the text that I want to be on line 2 of a.txt.  However, sed instead prints fname="$myaddress" to line 2 of a.txt, probably because it is inside the surrounding apostrophes.  In other words, the output of the above bash shell script is:   fname="/home/" A B C  A fname="$myaddress" C   My question is, how can I get sed to actually print the value stored in myaddress and referenced by $myaddress?
100466
0:root@SERVER:/root # echo "something" | sed -e 's/^/\t/g' tsomething 0:root@SERVER:/root #    AIX/ksh .. why doesn't it works? I just want to put a "tab" before every line!
65920
I have a input file FILE1.TXT as below.     11 id1   12   13 AGE = 20   14 NAME = NAME1   15   16 id2   17   18 AGE = 30   19 NAME = NAME2   .   .   .   110 idXYZ   111   112 AGE = AGEXYZ   113 NAME = NAMEXYZ   114   115 idZZZ   116     I want to search all the fields that belong to a particular Id and get the value for NAME  I managed to loop through each Id and formed the below command for each Id as required.  sed -n '/11/,/14/p' FILE1.TXT | grep NAME | awk -F "= " '{print $2}'  The problem here is, I get the output NAME1, in addition to that, I also get NAMEXYZ.  What should be changed so that I only get NAME1 but not NAMEXYZ?  As a workaround, the below commands work.  sed -n '/11/,/14/p' FILE1.TXT | grep NAME | awk -F "= " '{print $2}'|head -1  Is there any 'switch' or am I missing something?
81695
I have a file as below:  mime PI Name: ISHO SUCCESS RATE RT, Value: 95.663826 scr  PI Name: RRC Access Failures due to UU, Value: 0.13394141 prog PI Name: RRC Access Failures due to UU, Value: 0.16077702 sch PI Name: RRC Access Failures due to UU, Value: 0.11781933   I want to remove text PI till Value:. I tried   sed '/&lt;PI&gt;/,/&lt;\/Value:&gt;/d'    Any help?
53204
I have been trying to insert a file as the first line of another with following SED command, without much success. Each time the file is inserted after line 1. Is there a switch that will inserted before line 1?  sed -i '1r file1.txt' file2.txt   Thanks in advance.
92184
This  inserts a tag to the beginning of a file:  sed -i "1s/^/&lt;?php /" file   How can I insert something to the end of each file with sed?
8341
I'm going to submit form using cURL, where some of the contents is come from other file, selected using sed  If param1 is line matching pattern from other file using sed, below command will works fine:  curl -d param1="$(sed -n '/matchpattern/p' file.txt)" -d param2=value2 http://example.com/submit   Now, go to the problem. I want show only text between 2 matching pattern excluding the matching pattern itself.  Lets say file.txt contains:  Bla bla bla firstmatch It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. secondmatch The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.   Currently, lots of "beetween 2 matching pattern" sed command won't remove firstmatch and secondmatch.  I want the result to become:  It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.
40363
I'm trying to replace each , in the current file by a new line:  :%s/,/\n/g    But it inserts what looks like a ^@ instead of an actual newline. The file is not in DOS mode or anything.  What should I do?  If you are curious, like me, check the question  as well.
121845
inputs:  line1 with the PATTERN that contains ( )  line2 with the PATTERN that contains ( )  lineN with the PATTERN that contains ( )    outputs:  line1 with the PATTERN that contains ( ) ; line2 with the PATTERN that contains ( ) ; ... lineN with the PATTERN that contains ( ) ;   I tried this:  find . -name "test.txt" -print | xargs sed -i "/PATTERN/ s/$)/); /g"   but it didn't work.
106505
Using sed, how do I search for a line ending with foo and then edit the next line if it starts with #bar?  Or put another way, I want to remove a comment # from the next line if it starts with #bar and the previous line ends in foo.  For example:  This is a line ending in foo #bar is commented out There are many lines ending in foo #bar commented out again   I tried:  sed -i 's/^foo\n#bar/foo\nbar/' infile
17165
I'm trying to use sed to edit a config file. There are a few lines I'd like to change. I know that under Linux sed -i allows for in place edits but it requires you save to a backup file. However I would like to avoid having multiple backup files and make all my in place changes at once.  Is there a way to do so with sed -i or is there a better alternative?
98042
I'm reading a lot of documentation on sed, and am still stumped on my particular use case.  I want to replace this line in a conf file with my own line:  Replace this line: #maxmemory &lt;bytes&gt; with: maxmemory 26gb  This is what I tried:  sed s/maxmemory.*bytes.*/maxmemory 26gb/ /etc/redis/redis.conf  I get the error: sed: -e expression #1, char 30: unterminated `s' command  Which stumps me because I don't know what that means. So my question is:  How can I accomplish what I want? What does that error mean? (so I can learn from it)
26804
I'm so confused with GNU sed, POSIX sed, and BSD sed's myriad of options.  How do I replace literal \n with the newline character using these three sed types?