sed replace end of line

I'm trying to add a bunch of 0s at the end of a line. The way the line is identified is that it is followed by a line which starts with "expr1" in Vim what I do is: s/\nexpr1/ 0 0 0 0 0 0\rexpr1/ and it works fine. I know that in ubuntu \n is what is normally used to terminate the line but whenever I do that I get a ^@ symbol so \r works fine for me. I thought I'd use this with sed but it hasn't really worked. here is what I normally write: sed "s/\nexpr1/ 0 0 0 0 0 0\rexpr1/" infile > o

sed only substitutes first occurrence of string

I use sed to create files from template files. I can't figure out, using man sed, why it does not change all the matched strings. If my file (template_file.txt) contains: #!/bin/sh # # /etc/init.d/%SCRIPT_NAME% - Startup script for play %SCRIPT_NAME% engine # ### BEGIN INIT INFO [...] EOF Using : sed -e "s;%SCRIPT_NAME%;script_test_name;" template_file.txt > script_test_name Produces (script_test_name) : #!/bin/sh # # /etc/init.d/script_test_name - Startup script for play %SCRIPT_NAME

sed/awk to double space file

I have a file with blank lines and I need to double space the lines in the file. Meaning I need a blank line between two lines with text in it. Can you show me an easy way to do it with awk and/or sed

Combining two sed commands

I have a file r. I want to replace the words File and MINvac.pdb in it with nothing. The commands I used are sed -i 's/File//g' /home/kanika/standard_minimizer_prosee/r and sed -i 's/MINvac.pdb//g' /home/kanika/standard_minimizer_prosee/r I want to combine both sed commands into one, but I don't know the way. Can anyone help? The file looks like this: -6174.27 File10MINvac.pdb -514.451 File11MINvac.pdb 4065.68 File12MINvac.pdb -4708.64 File13MINvac.pdb 6674.54 File14MINv

Sed Extract last tuple

I have a text file of mysqldump commands. It looks something like this... INSERT INTO `agent_new` VALUES ('1', 'abc'), ('2', 'xyz'), ('3', 'pqr'); I need the last entry from the list of tuples. I also need the table name. So the expected output will be INSERT INTO `agent_new` VALUES ('3', 'pqr'); The last row will always have a semi colon at the end for e.g. 'pqr'); I need to extract the last row to compare with the actual database. I can do "tail" but I will like to know if there is any

Sed print first column and print everything after % sign

I want to print the first column in this case the host IP and everything after % character. 3558: 003557: Mar 4 2013 12:13:28: %LINEPROTO-SP-5-UPDOWN: Line protocol on Interface GigabitEthernet8/37, changed state to up : 2013 Mar 4 13:14:20 EST: %ETHPORT-5-IF_DOWN_LINK_FAILURE: Interface Ethernet17/33 is down (Link failure)

awk/sed broken line how to fix and move some lines

I have a few lines that are broken and I want those lines to be moved up to the prior line I need help to fix this file text Source: Path : Microsoft.PowerShell.Core\FileSystem::\\eiesc1\Ser vice_Legal Access : BUILTIN\Administrators Allow FullControl MLIDDOMAIN1\Domain Admins Allow FullControl MLIDDOMAIN1\acl_corp_gs_legal Allow Modify, Synchronize ----------------------- Path : Microsoft.PowerShell.Core\FileSystem::\\eiesc1\balc

Using sed in terminal to replace text in file

I have this text in this file: test.php $databases = array ( 'default' => array ( 'default' => array ( 'database' => 'original', 'username' => 'root', 'password' => 'root', 'host' => 'localhost' ), ), ); In terminal run this line to replace 'original' with 'new' sed -i 's/original/new/g' test.php UPDATE: The error message is: sed: 1: "test.php": undefined label 'est.php' What is the problem? UPDATE 2: If I just run: (

How do I perform this modify or insert line with sed correctly?

I am running this on a test crontab file with these contents: 00 01 * * * foo --file example/example.xml --bla 00 02 * * * foo --file abc/abc.xml --bla I am trying to replace the first line (if it exists) with something else, say 'bar', or inserting the bar line if it could not find it at all by running this: sed -e '@\(.*file example/example.xml .*\)@bar@' -e t -e 's@^@bar@' file I would expect the above to try to replace a matching example line with bar, and if it does not find it to ins

Sed compare first 60 characters and delete the duplicate row

How to use the sed to check the consecutive lines where there first 10 characters is the same? If same, the second row of the lines will be deleted. Example: Before ABCDEF123456 123456ABCDEF 123456789012 123456789090 After ABCDEF123456 123456ABCDEF 123456789012

sed :add a column to a file with two values

I need to a add a column (the same values) with a column name to a already existing tab-delimited file. I don't want to create a new file etc. A B C D 1 1 1 1 1 1 1 1 I need a new Column with a header Z containing only one value 2 across all rows. A B C D Z 1 5 1 2 2 0 6 1 0 2 How can I do it with sed? My idea was sed "1i Z" | sed "s/$/&\t2/". But 1li adds a header of course.

Using sed to keep the beginning of a line

I have a file in which some lines start by a > For these lines, and only these ones, I want to keep the first eleven characters. How can I do that using sed ? Or maybe something else is better ? Thanks ! Muriel

Sed replace sql

page.sql Replace the following script INSERT INTO `page` by this: INSERT INTO `page` (page_id, page_namespace, page_title, page_restrictions, page_counter, page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len) I am a beginer,I don't know what's wrong with this GNU Sed command on windows: sed 's/INSERT INTO `page`/INSERT INTO `page` (page_id, page_namespace, page_title, page_restrictions, page_counter, page_is_redirect, page_is_new, page_random, page_touched, p

Sed not finding and replacing

I have a file that I am translating to Chinese and some of the strings are not being detected. I'm guessing it has something to do with the '1' Here's and example of something that my sed statement isnt catching sed -i 's|('1' = enabled)|('1'=启用)|' TranslatedDiag.txt How should I encapsulate this?

Delete multiple patterns using sed

I have data in below format SQL> BEGIN Oracle Query; END; SQL> 123 : TEST ABC 345 : Yes ----------------- 123 : TEST BDE 345 : Yes ----------------- PL/SQL procedure successfully completed. SQL> Disconnected from Oracle Database 12c Enterprise Edition Release I want to get data into below format :-- 123 : TEST ABC 345 : Yes

Match and replace block using regex with sed on Solaris

This is working on some tools as but I cannot make it work with sed. Blocks: dn: abcd1,ou=test aaaaa bbbb 1111 dn: abcd2,ou=test 33333 ddddd aaaaa dn: qwert,ou=test 55555 hhhh dddd I want to match and replace with nothing every block that starts with dn: abcd. A block always ends with \n\n. Regexp: (?s)\b(?:(?!\n\n).)*?\bdn: abcd\b(?:(?!\n\n).)* Is it possible to achieve with sed?

Sed how to replace empty double quotes with some value

i have a xml with below syntax <test key="NAME1" value=""> <test key="NAME2" value=""> How to replace value with empty string with some values based on the key name, using sed command. With something like this <test key="NAME1" value="123"> <test key="NAME2" value="234">

How to update a specific key in a specific section using sed?

I have an ini file similar to the following one: [seciton1] key1 = 0 key2 = 0 [section2] key1 = 0 key2 = 0 I want to update key1 of section "section2" from 0 to 1. what will be the accurate sed command for the same. also is sed command supported in SSH.NET c# library? if not then what are the ways using we can update ini file.

sed Remove lines between two patterns (excluding end pattern)

given text like _adsp TXT "dkim=all" VVKMU6SE3C2MF88BG4DJQAECMR9SIIF0 NSEC3 1 1 10 C4F407437E8EA4C5 ( 175MCHR31K25LP89OVJI5LCE0JA2N2AP A MX TXT AAAA RRSIG SPF ) RRSIG NSEC3 7 3 1800 ( 20200429171433 20200330161758 11672 H3l26qmtkuiFZCeSYCCAo5krFE3gjM0I8UeQ9jhj3STy X6fM0YizCHEuv4VZynOJGJc1XJnHRHI+p7yLlZ+OVseK UfIkPVP+VOmlerwozEpM+Tnt8evwnMTDbcn0zxf/6YJx

How to prevent replacement by subsequent s/// (empty pattern for replacement) in sed?

sed removes the character 'a' in the last example, because when sed is passed the subsequent s command with an empty pattern, the previous one is used, in this case, $a instead empty $c, which is 'a'. The POSIX specification for sed If an RE is empty (that is, no pattern is specified) sed shall behave as if the last RE used in the last command applied (either as an address or as part of a substitute command) was specified. In a real script, variables $c $d can be either empty or defined. For d

Nested delimiter problem with gawk/sed

I've this text that I need to split: [{names: {en: 'UK 100', es: 'UK 100'}, status: 'A', displayed: 'Y', start_time: '2011-05-12 00:00:00', start_time_xls: {en: '12th of May 2011 00:00 am', es: '12 May 2011 00:00 am'}, suspend_at: '2011-05-12 15:14:02', is_off: 'Y', score_home: '', score_away: '', bids_status: '', period_id: '', curr_period_start_time: '', score_extra_info: '', settled: 'N', ev_id: 2666872, ev_type_id: 10744, type_name: '|UK 100|'}, {names: {en: 'US 30', es: 'US 30'}, status:

Sed replace ';' with ';\n'

How can I replace ; with ;\n (semicolon followed by a newline) in sed? I've tried building off of sed s/;/\\n/g file and sed -e '/;/G' file but I can't get either to work

Using sed to find and append multiple files with multiple lines?

Hi I'm trying to append a few lines of codes to a couple thousand html files in a directory (and sub-directories). What I'm trying to do is add xxx lines of code to all html files following the tag. I've tried to explore sed but I'm having issues with having the / sign inside the search and adding the several lines of codes to the sed command. I'm thinking of adding the lines I want to add in a txt file and use sed to place all content in that txt file after the tag. Much appreciate any help

sed replace PATH in .bashrc

I have the following entry in my .bashrc: PATH=$PATH:/home/user/abc/bin;export PATH; # ADDED BY INSTALLER - DO NOT EDIT OR DELETE THIS COMMENT I want to substitute /home/user/abc/bin for any path that I choose. How can I do this with sed? I have the following: sed 's,PATH=[^;]*,PATH=$PATH/home/user/app/2.1,' -i ~/.bashrc But, this will substitute anything that begins with PATH, how can I specify to only select what begins with PATH but also includes the string ADDED BY INSTALLER - DO NOT

Sed Remove all words after starting from a specific word

How do I remove all the words starting from COMMENT word in the following string? echo "first_mail_sent_date_time datetime NOT NULL COMMENT 'The date and time'," | sed 's/ COMMENT \w*/ /g' The above sed command will remove only the word COMMENT. I need to remove everything after COMMENT but keep the last comma. I can use awk but I am looking for sed solution for consistency sake. awk -F'COMMENT' '{print $1 ","}'

Sed How can I rewrite the terminal output of a program

I'm running an application (CoronaSDK Simulator) from the terminal that puts an insanely long timestamp in front of every line of output. Is there a way to use something like sed to chop it off and instead output everything else as it comes in (i.e. without having to wait until the program ends)? I've tried a couple of things, but have had no luck so far... Here are some sample lines: 2013-02-14 12:39:49.028 Corona Simulator[40803:707] |timer created 2013-02-14 12:39:49.029 Corona Simulator[

Sed Add symbol between characters of MAC Addresses

I have a list of MAC Addresses and I need to add a ":" every 2 characters. I mean, if I have this: 23396 - FFFF00400001 - Lantastic 23397 - FFFF01E00004 - Lantastic 23379 - 0C000C0000 - ISL-Frame 23054 - F8D756 - Simm Tronic Limited 23055 - F8D7BF - REV Ritter GmbH I need to parse to have this: 23396 - FF:FF:00:40:00:01 - Lantastic 23397 - FF:FF:01:E0:00:04 - Lantastic 23379 - 0C:00:0C:00:00 - ISL-Frame 23054 - F8:D7:56 - Simm Tronic Limited 23055 - F8:D7:BF - REV Ritter GmbH It is possib

GNU sed specify the end position when appending text

I want to do two things by sed when matching a pattern: Replace the pattern with a string Append another string after this line Such as the original content in a text file is: abc 123 edf I want to replace 123 to XXX and append YYY after the line: abc XXX YYY edf I tried to do this by sed '/123/{s/123/XXX;a\YYY\}', but it gave an error: Unmatched "{". It seemed that command a treats all characters after it as text to append. So how can I make a know the end position of the text for a

Unable to use sed to customize buffer size in mariadb Dockerfile

I'm trying to customize a mariadb container so that it has an increased innodb buffer size. My ideal scenario would be to use sed so I don't have to maintain a duplicate my.cnf config file. Here's my Dockerfile, but it doesn't replace the value like I'd expect and I"m not sure what I'm doing wrong... FROM mariadb:10.1 RUN sed -ri 's/innodb_buffer_pool_size\\ =\\ 256M/innodb_buffer_pool_size\\ =\\ 512M/g' /etc/mysql/my.cnf \ && cat /etc/mysql/my.cnf | grep innodb; The output of

how to ouput sed/samtools result into new directory

I have the following sed command that change the chromosome name: for file in /myoldpath/*.bam; do filename=`echo $file | cut -d "." -f 1`; samtools view -H $file | sed -e 's/SN:\([0-9XY]\)/SN:chr\1/' -e 's/SN:MT/SN:chrM/' | samtools reheader - $file > /mynewpath/${filename}_chr.bam; done My quesion is how to insert the result in a new path while keeping the variable $filename as part of every new file name? It always inserts the result in /myoldpath/ or leterally "filename.chr.bam" in t

get some field of text with sed command

I have these line: "CN=Michael George\, Jou,OU=External,OU=User,DC=Company,DC=en" I would like to extract these: Michael George\, Jou I'm trying with sed: grep -i "CN" file | sed "s/CN=\(.*\),\(.*\)/\1/g" But I can't have these result. Could you help me with sed command? Thanks

Make single instance of `sed` with multiple filenames skip to next file

The next command in sed skips to the next line, but with multiple files there doesn't seem to be any command to skip to the next file. Is there any workaround using only a single invocation of sed? Demonstration of problem... Make two simple 3-number data files: seq 3 > three ; seq 10 1 13 > thirteen Show that sed handles multiple files, (by finding all lines ending with 3 and printing the filenames), and is somewhat aware of them as distinct objects: sed -n '/3$/{p;F}' three thirtee

how to use sed to pull out data from a hex file

I want to use sed to pull out data from a hex file but i dont want any hex formats output to the screen I'm wanting to pull out any words from A to Z or a to z that have a minimum length of 5 characters and a maximum length of 25 characters Is there a way to do this with sed and awk

Using sed I want to delete "... 12 more" / "... 14 more" string from java stack trace

I have a use case were I want to remove "... 12 more" / "... 14 more" string from java stack trace For an example : at org.apache.hadoop.hdfs.server.datanode.DataNode.createDataNode( at org.apache.hadoop.hdfs.server.datanode.DataNode.secureMain( at org.apache.hadoop.hdfs.server.datanode.DataNode.main( Caused by: java.lang.SecurityException: Can not initialize cryptographic mechanism at javax.crypto.JceSecurity.<clinit

Sed how to create subset of large file with echo tail

I want to open a large error log file (with millions of lines). To investigate, I just need to look at the recent log. So I would like to copy the "tail" result of the large file to a new file. How to get it? echo "tail largefile.log" > lastline.txt Something like this. But I need the output of tail largefile.log to be inside lastline.txt This can also be achieved using "sed" command, I guess.

Sed how to use '^' char in a replace expression

I want to use sed to replace some strings containing '^' in a text file The original string (" are part of the string) "POINT(5.94462 45.569924)^^geo:wktLiteral" the expected substituted string "POINT(5.94462 45.569924)"^^geo:wktLiteral I've tried sed -i 's/\^\^geo:wktLiteral\"/\"\^\^geo:wktLiteral/' myFile or sed -i 's/\x5e\x5egeo:wktLiteral\"/\"\x5e\x5egeo:wktLiteral/' myFile these two solutions do not work. Any help is welcome.

Have sed make substitute on string but SKIP first occurrence

I have been through the sed one liners but am still having trouble with my goal. I want to substitue matching strings on all but the first occurrence of a line. My exact usage would be: $ echo 'cd /Users/joeuser/bump bonding/initial trials' | sed <<MAGIC HAPPENS> cd /Users/joeuser/bump\ bonding/initial\ trials The line replaced the space in bump bonding with the slash space bump\ bonding so that I can execute this line (since when the spaces aren't escaped I wouldn't be able to cd

How to use sed to remove all double quotes within a file

I have a file called file.txt. It has a number of double quotes throughout it. I want to remove all of them. I have tried sed 's/"//g' file.txt I have tried sed -s "s/^\(\(\"\(.*\)\"\)\|\('\(.*\)'\)\)\$/\\3\\5/g" file.txt Neither have worked. How can I just remove all of the double quotes in the file?

unix sed, replace field at a specific row and column in the same file

I have a text file with 4 columns delimited by comma. As I am reading each record in a loop, I want to add a value to the 5th column depending on a condition. So if I know the row number and column number, how can I use awk/sed commands to replace/set value at that particular field without using temporary files? I want to update the file (directly) that I am reading from inp.txt a,b,c,d e,f,g,h i,j,k,l Thanks, -sri

Sed Replace all double quotes with single quotes

I'm trying to replace all double quotes in a string with single quotes. here my expression: echo "<a href=\"#\" id=\"resendActivationMailLink\">here</a>" | sed "s/\"/'/" unfortunately only the first double quote is replaced :S <a href='#" id="resendActivationMailLink">here</a> any Ideas?

Sed Move last column title name and put to be on first column on all rows

Want to get the last column in the title in that example is "db5b", and to place in to the first column on every next row. Output: Filesystem utilization for db5b /dev/hd4 3.00 2.87 5% 5728 1% / /dev/hd2 7.00 2.79 61% 61845 9% /usr /dev/hd9var 7.00 5.88 17% 861 1% /var /dev/hd3 3.00 2.98 1% 205 1% /tmp Expected result: db5b 5% / db5b 61% /usr db5b 17% /var d

How to use sed to delete lines which have certain pattern and at some specific line range?

This is the command working for me: sed "50,99999{/^\s*printf/d}" the_file So this command delete all the lines between 50 and 99999 which have "printf" in it and there is only whitespace before printf at the line. Now my questions are: how to replace 99999 with some meta symbol to indicate the real line number I tried sed "50,${/^\s*PUTS/d}" the_file, but it is not right. how to replace "printf" with an environment variable? I tried set pattern printf sed "50,99999{/^\s*$pattern/d}" th

Sed sh - remove text outside two strings

I need help to filter a part of text from my original logs: <variable> <status type="String"><![CDATA[-1]]></status> <errorCode type="String"><![CDATA[[bpm]]]></errorCode> <mensagens type="MensagemSistema[]"> <item> <msg_err type="String"><![CDATA[ERROR1-This is error: - THIS TEXT IS VARIABLE.]]</msg_err> <msg_err_stack type="String"><![CDATA[stack_trace]]></msg_err_stack> <

How do I use sed properly to insert text into a file using a variable?

How do I use sed properly to insert text into a file using a variable? MYNIC_IP=`ip addr show eth0 | grep eth0 | awk '{ print $2; }' | sed 's/\/.*$//'` Ok cool. echo $MYNIC_IP eth0: sudo sed -i -e '1i'$MYNIC_IP /usr/share/nginx/html/index.html This results in part of the variable being added... just eth0:

How to rearrange numbers using SED (transposition)

I have a line: The ID number for product is 721- 971-4321.` I want to swap the area code and exchange it for the number inside, like so: 971- 721-4321 Here is what I have: 17s/\([654]\)-\([817]\)/\2-\1/ So the number is on line 17 in a .txt file. There is other stuff on the line but I want to only change the number. Whenever I run the script nothing happens. Any advice how to fix this.

sed replace a word and it's previous word seperated by delimeter

I have a file and in it there are many occurances of *.client which i wanna replace with tbot like ~ await event.client.send_file(bla bla) await master.client.send_message(bla bla) await iter.client.get_entity(bla bla) and i wanna replace them like ~ await tbot.send_file(bla bla) await tbot.send_message(bla bla) await tbot.get_entity(bla bla) I tried something like sed -i 's/*.client/tbot/g' thefile but didn't work, any solutions ?

  1    2   3   4   5   6  ... 下一页 最后一页 共 14 页