sed

sed replacement does not work

Hello, I have trouble using sed. I need to replace some lines in very deprecated HTML sites which consist of many files. My script does not work and I do not why. When I tried to find exact pattern with Netbeas it worked. find . -type f -name "*.htm?" -exec sed -i -r 's/ing\. Šuhajda Dušan\, Mírová 767\, 518 01 Dobruška\, \+420 737 980 ...

Regular Expression: back references

sed 's/^\(\h*\)\(.*\)$/\1<!-- \2 -->/' web.xml I think that this should take this xml: <a> <d> bla </d> </a> And turn it into: <!-- <a> --> <!-- <d> --> <!-- bla --> <!-- </d> --> <!-- </a> --> But what is doing is this: <!-- <a> --> <!-- <d> --> <!-- bla --> <!-- </d> --> <!-- </a> --> ...

Why does this regular expression for sed break inside Makefile?

I'm using GNU Make 3.81, and I have the following rule in my Makefile: jslint : java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \ | sed 's/Lint at line \([0-9]\+\) character \([0-9]\+\)/mango.js:\1:\2/' This works fine if I enter it directly on the command line, but the regular expression does not match if I ru...

Sed: regular expression match lines without <!--

I have a sed command to comment out xml commands sed 's/^\([ \t]*\)\(.*[0-9a-zA-Z<].*\)$/\1<!-- Security: \2 -->/' web.xml Takes: <a> <!-- Comment --> <b> bla </b> </a> Produces: <!-- Security: <a> --> <!-- Security: <!-- Comment --> --> // NOTE: there are two end comments. <!-- Security: <b> --> <!-- ...

Redirect output from sed 's/c/d/' myFile to myFile

I am using sed in a script to do a replace and I want to have the replaced file overwrite the file. Normally I think that you would use this: % sed -i 's/cat/dog/' manipulate sed: illegal option -- i However as you can see my sed does not have that command. I tried this: % sed 's/cat/dog/' manipulate > manipulate But this just ...

awk - Remove line if field is duplicate

Looking for an awk (or sed) one-liner to remove lines from the output if the first field is a duplicate. An example for removing duplicate lines I've seen is: awk 'a !~ $0; {a=$0}' Tried using it for a basis with no luck (I thought changing the $0's to $1's would do the trick, but didn't seem to work). ...

binary sed replacement

I was attempting to do a sed replacement in a binary file however I am beginning to believe that is not possible. Essentially what I wanted to do was similar to the following: sed -bi "s/\(\xFF\xD8[[:xdigit:]]\{1,\}\xFF\xD9\)/\1/" file.jpg The logic I wish to achieve is: scan through a binary file until the hex code FFD8, continue re...

Sed not reconizing \t instead it is treating it as 't' why?

sed "s/\(.*\)/\t\1/" $filename > $sedTmpFile && mv $sedTmpFile $filename I am expecting this sed script to insert a tab in font of every line in $filename however it is not. For some reason it is inserting a t instead.. Strange.. ...

How to sed search and replace without changing ownership

I found this command line search and replace example: find . -type f -print0 | xargs -0 sed -i 's/find/replace/g' It worked fine except it changed the date and file ownership on EVERY file it searched through, even those that did not contain the search text. What's a better solution to this task? Thanks. ...

[sed] Multiline trimming

I have a html file that I want to trim. I want to remove a section from the beginning all the way to a given string, and from another string to the end. How do I do that, preferably using sed? ...

Replacing Part of Text Using Sed

I have the following text file Eif2ak1.aSep07 Eif2ak1.aSep07 LOC100042862.aSep07-unspliced NADH5_C.0.aSep07-unspliced LOC100042862.aSep07-unspliced NADH5_C.0.aSep07-unspliced What I want to do is to remove all the text starting from period (.) to the end. But why this command doesn't do it? sed 's/\.*//g' myfile.txt What's the righ...

Replacing multiple bar (special char) with tab using sed

I have a string like this BRADI5G20430|BRADI5G20430.1||1 How can I replace the bar (single and multiple) with tab ("\t")? I tried this but dont' work sed 's/\|+/\t/g' I also want to include this line in bash script. ...

Creating multiple csv files from data within a csv file.

System OSX or Linux I'm trying to automate my work flow at work, each week I receive an excel file, which I convert to a csv. An example is: ,,L1,,,L2,,,L3,,,L4,,,L5,,,L6,,,L7,,,L8,,,L9,,,L10,,,L11, Title,r/t,needed,actual,Inst,needed,actual,Inst,needed,actual,Inst,needed,actual,Inst,neede d,actual,Inst,needed,actual,Inst,needed,actua...

Bash: Extract Range with Regular Expressioin (maybe sed?)

I have a file that is similar to this: <many lines of stuff> SUMMARY: <some lines of stuff> END OF SUMMARY I want to extract just the stuff between SUMMARY and END OF SUMMARY. I suspect I can do this with sed but I am not sure how. I know I can modify the stuff in between with this: sed "/SUMMARY/,/END OF SUMMARY/ s/replace/with/" ...

Redirect sed output to tr

How do I redirect the output of a sed command as input to a tr command? ...

Can sed be made recursive in for windows?

I'm using sed for windows to do search and replace on some javascript files, and I was wondering if using some other utility I could make it work recursively. ...

How to format a dos path to a unix path on cygwin command line

When using Cygwin, I frequently copy a Windows path and manually edit all of the slashes to Unix format. For example, if I am using Cygwin and need to change directory I enter: cd C:\windows\path then edit this to cd C:/windows/path (Typically, the path is much longer than that). Is there a way to use sed, or something else t...

Remove a line from a csv file bash, sed, bash

I'm looking for a way to remove lines within multiple csv files, in bash using sed, awk or anything appropriate where the file ends in 0. So there are multiple csv files, their format is: EXAMPLEfoo,60,6 EXAMPLEbar,30,10 EXAMPLElong,60,0 EXAMPLEcon,120,6 EXAMPLEdev,60,0 EXAMPLErandom,30,6 So the file will be amended to: EXAMPLEfoo,...

Parsing the first column of a csv file to a new file.

Operating System: OSX Method: From the command line, so using sed, cut, gawk, although preferably no installing modules. Essentially I am trying to take the first column of a csv file and parse it to a new file. Example input file EXAMPLEfoo,60,6 EXAMPLEbar,30,6 EXAMPLE1,60,3 EXAMPLE2,120,6 EXAMPLE3,60,6 EXAMPLE4,30,6 Desire output...

Merge two text files at a specific location, sed or awk.

I have two text files, I want to place a text in the middle of another, I did some research and found information about adding single strings: I have a comment in the second text file called STUFFGOESHERE, so I tried: sed '/^STUFFGOESHERE/a file1.txt' file2.txt sed: 1: "/^STUFFGOESHERE/a long.txt": command a expects \ followed by te...