sed

Susbtitution in sed with spaces

Hi, I have the following variable in bash: var1="this is ok" and in a file I want fo make in all lines the subst: _day 23. 45. 56. ... to this is ok_day 23. 45. 56. so I add var1 to the start of the line I tried with this sed -e "s/_/${var1}"_"/g" ${filename} but i get errors I do not know if this is because the spaces. I...

How can I change from a sed to Perl statement in command line?

Hi everyone, I need to search a phrase in multi files and display the results on the screen. grep "EMS" SCALE_* | sed -e "s/SCALE_//" -e "s/_main_.*log:/ /" Since I am not get familiar with sed, I change it to Perl for convenient use. grep "EMS" SCALE_* | perl -e "s/SCALE_//" -e "s/_main_.*log:/ /" or grep "EMS" SCALE_* | perl -...

Control Processes Started by Bash Daemon

In bash, I have created a simple daemon to execute commands when my internet connection changes: #!/bin/bash doService(){ while do checkTheInternetConnection sleep 15 done } checkTheInternetConnection(){ if unchanged since last check return else execute someCommand fi } someCommand(){...

Help with sed regex: extract text from specific tag

First time sed'er, so be gentle. I have the following text file, 'test_file': <Tag1>not </Tag1><Tag2>working</Tag2> I want to extract the text in between <Tag2> using sed regex, there may be other occurrences of <Tag2> and I would like to extract those also. So far I have this sed based regex: cat test_file | grep -i "Tag2"| sed '...

Modifying Text Column Wise with Sed/AWK

I have an input data with three columns (tab separated) like this: a mrna_185598_SGL 463 b mrna_9210_DLT 463 c mrna_9210_IND 463 d mrna_9210_INS 463 e mrna_9210_SGL 463 How can I use sed/awk to modify it into four columns data that looks like this: a mrna_185598 SGL 463 b mrna_9210 DLT 463 c mrna_9210 ...

Using sed to delete a case insensitive matched line

How do I match a case insensitive regex and delete it at the same time I read that to get case insensitive matches, use the flag "i" sed -e "/pattern/replace/i" filepath and to delete use d sed -e "/pattern/d" filepath I've also read that I could combine multiple flags like 2iw I'd like to know if sed could combine both i and d I've t...

G++ and sed pipeline

Hello, I would like to replace all "no" by "on" in the console output of g++. I tried $ g++ | sed -e 's/no/on/g' But it shows i686-apple-darwin9-g++-4.0.1: no input files instead of i686-apple-darwin9-g++-4.0.1: on input files ...

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 ...

editing text files with perl

I'm trying to edit a text file that looks like this: TYPE=Ethernet HWADDR=00:.... IPV6INIT=no MTU=1500 IPADDR=192.168.2.247 ... (Its actually the /etc/sysconfig/network-scripts/ifcfg- file on red hat Linux) Instead of reading and rewriting the file each time I want to modify it, I figured I could use grep, sed, awk or the native text ...

Replacing all GUIDs in a file with new GUIDs from the command line

I have a file containing a large number of occurrences of the string Guid="GUID HERE" (where GUID HERE is a unique GUID at each occurrence) and I want to replace every existing GUID with a new unique GUID. This is on a Windows development machine, so I can generate unique GUIDs with uuidgen.exe (which produces a GUID on stdout every tim...

Need help interpreting this sed command

I'm looking through an Oracle script I found online, but it runs a sed command to filter results from a trace file. I'm running Oracle on a Windows server, so the sed command isn't recognized. host sed -n '/scattered/s/.*p3=//p' &Trace_Name | sort -n | tail -1 I've tried reading the online documentation, but am still not sure how to ...

SVG to black-and-white

Hi, I would like to be able to convert SVG documents to black and white. My try is the following Makefile script using 'sed' : %.bw.svg: %.svg sed '/stroke:none/!s/stroke:[^;\"]*/stroke:black/g' $< > $@ This works for lines etc but not for fillings. Basically if the stroke is not invisible (none), then I convert it to black. I wou...

Sed or Ruby for mundane text processing / dev-productivity tools creation.

I want to learn Sed. Can you please point me to good references so that I can fully utilize it. I want to learn it to perform more of the do-once-then-forget type administrative or dev-tools like tasks. So, I don't really care about performance or modularity or object orientedness etc when writing this type of code. Do you think it wou...

Using awk (or sed) to remove newlines based on first character of next line

Hello everyone, here's my situation: I had a big text file that I wanted to pull certain information from. I used sed to pull all the relevant information based on regexp's, but each "piece" of information I pulled is on a separate line, I'd like for each "record" to be on its own line so it can be easily imported into a DB. Here's a sam...

Match URL link from input string

How do I match the URL address in this string, I have other code that matches text and it seems to work, but when I try to use it here, it doesn't, it keeps saying there is "No such file or directory. I didn't know grep -o only worked on files? matchString='url={"urlPath":"http://www.google.com/","thisIsOtherText"' array=($(grep -o 'url...

With sed or awk, how do I match from the end of the current line back to a specified character?

I have a list of file locations in a text file. For example: /var/lib/mlocate /var/lib/dpkg/info/mlocate.conffiles /var/lib/dpkg/info/mlocate.list /var/lib/dpkg/info/mlocate.md5sums /var/lib/dpkg/info/mlocate.postinst /var/lib/dpkg/info/mlocate.postrm /var/lib/dpkg/info/mlocate.prerm What I want to do is use sed or awk to read f...

Match domain name from url (www.google.com=google)

So I want to match just the domain from ether: http://www.google.com/test/ http://google.com/test/ http://google.net/test/ Output should be for all 3: google I got this code working for just .com echo "http://www.google.com/test/" | sed -n "s/.*www\.\(.*\)\.com.*$/\1/p" Output: 'google' Then I thought it would be as simple as doin...

Concatenating multiple lines with a discriminator

I have the input like this Input: a,b,c d,e,f g,h,i k,l,m n,o,p q,r,s I wan to be able to concatenate the lines with a discriminator like "|" Output: a,b,c|d,e,f|g,h,i k,l,m|n,o.p|q,r,s The file has 1million lines and I want to be able to concatenate lines like the example before. Any ideas about how to approach this? ...

Extraction of data from a simple XML file

I've a XML file with the contents: <?xml version="1.0" encoding="utf-8"?> <job xmlns="http://www.sample.com/"&gt;programming&lt;/job&gt; I need a way to extract what is in the <job..> </job> tags, programmin in this case. This should be done on linux command prompt, using grep/sed/awk. ...

What's the clearest way to replace trailing backslash \ with \n?

I want multi-line strings in java, so I seek a simple preprocessor to convert C-style multi-lines into single lines with a literal '\n'. Before: System.out.println("convert trailing backslashes\ this is on another line\ \ \ above are two blank lines\ But don't convert non-trailing backslashes, like: \"\t\" and \'\\\'"); After: ...