sed

Extract all the links between specified html tags from an html file with sed

Hi everybody. Well I must find a way to extract all the links between <div id="links"> and </table> tags. And if there is more than one link, it should add '\n' character between the urls: "$URL1\n$URL2". <div id="links"> <table> <td><a href="URL">url</a></td> <td><a href="URL">url</a></td> </table> <table> .. </table> </div> The ones...

Regexp for replacing quotes in database insert statements

I'm converting a sqlite3 database to mysql. I have a nice command file for sed that changes AUTOINCREMEMT and the other things needed, but I'm stuck on the last one: double quotes. sqlite3 dump format: CREATE TABLE "products" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "desc" varchar(255) ); INSERT...

Why doesn't this regex work?

The regex: ^ *x *\=.*$ means "match a literal x preceded by an arbitrary count of spaces, followed by an arbitrary count of spaces, then an equal sign and then anything up to the end of line." Sed was invoked as: sed -r -e 's|^ *x *\=.*$||g' file However it doesn't find a single match, although it should. What's wrong with the reg...

Calling SED for a source in Makefile.am

I've got c++ code that needs a sed done to it prior to compilation. How do I place this into Makefile.am? I tried the typical makefile setup and the target appears to not exist: gentest.cc: $(SED) -i "s|FIND|REPLACE|" gentest.cc If you are interested as to why I want to do this, it's because I wrote my program (slid...

Replacing all the numbers with their currency format in given line of text

I want to write a Shell (AWK, Sed also fine) program to take as a input a SINGLE line of text. Which will have arbitrarily spread integer strings in it. e.g "12884 and 111933 are two numbers and 323232 is also a number" I want the output to be "12,884 and 1,11,933 are two numbers and 2,23,232 is also a number" If this was PHP a sim...

Replace an XML element's value? Sed regular expression?

I want to take an XML file and replace an element's value. For example if my XML file looks like this: <abc> <xyz>original</xyz> </abc> I want to replace the xyz element's original value, whatever it may be, with another string so that the resulting file looks like this: <abc> <xyz>replacement</xyz> </abc> How would you do...

What's what awk can't that sed can?

Or just a matter of choice and call awk and sed equivalent towards usage. They both do the common search replace seemingly identically regarding i/o. ...

Replacing huge blocks with sed

Hi. I have 2 files that are generated elsewhere. First one is "what to search", and second one is the replacement. Both files are huge, about 2-3mb each. I need to write a bash script that takes an even bigger file (about 200-300mb) and replaces all occurrences of file1 contents to file2 contents. Problem is, file1 and file2 can conta...

specify directory for C++ object files and executable in Makefile

Hi I am using gcc -MM to generate prerequisites of dependencies rules for compiling source files into object files. I want to specify a directory to hold object files and executable in the value of some variable BIN_DIR=bin/release/. There are two cases: CASE 1 %.d: *.h *.cc Makefile @$(CXX) -MM $(CXXFLAGS) *.cc > $@.$$$$; \ ...

Use find, wc, and sed to count lines

I was trying to use sed to count all the lines based on a particular extension. find -name '*.m' -exec wc -l {} \; | sed ... I was trying to do the following, how would I include sed in this particular line to get the totals. ...

sed not retrieving all values for second parameter

I am trying to have the command run to extract a range of dates from a file and print them ex: sed -ne '/^2009-08-20/,/^2009-08-26/p' Yet I have multiple occurances of 2009-08-26 in the file, I want all of them to return, yet it only returns the first one. Is it possible to have ALL return? Thanks! ...

How do I use a new-line replacement in a BSD sed?

Greetings, how do I perform the following in BSD sed? sed 's/ /\n/g' From the man-page it states that \n will be treated literally within a replacement string, how do I avoid this behavior? Is there an alternate? I'm using Mac OS Snow Leopard, I may install fink to get GNU sed. ...

How to search for a pattern inside a file and delete the lines in Unix on the command line?

I need to search for a pattern in files. For example the content of the file is below: 3555005!K!00630000078!C!20090805235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078! 3555005!K!204042880166840!I!20090805235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078! 3555005!D!16042296!DUMMY...

awk gives the following error

"awk: Function systime is not defined." but systime is a built in command ...

In a batch file, is it possible to replace this use of SED and TR with a for loop ?

the batch file: @echo. @set curdrive=%~d0 @path | %curdrive%\utils\sed -e "s/PATH=//" | %curdrive%\utils\tr ; \n @echo. Sample output (one path element on each line): C:\cheeso\bin C:\Perl\bin c:\utils C:\Windows\system32 C:\Windows C:\Windows\System32\Wbem c:\Program Files\Microsoft SQL Server\90\Tools\binn\ c:\.net3.5 c:\.net2.0 c...

Delete a line with a pattern

Hi I want to delete a line from a file which matches particular pattern the code I am using is BEGIN { FS = "!"; stopDate = "date +%Y%m%d%H%M%S"; deletedLineCtr = 0; #diagnostics counter, unused at this time } { if( $7 < stopDate ) { deletedLineCtr++; } else ...

replace words using grep and sed in shell

I have some 150 files and in them I want to remove this following code: <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/height.js"></SCRIPT> What I'm doing is: sed -e 's/<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/height.js"></SCRIPT>/ /' file_names This doesn't seem to work. I want to remove this script...

sed replace command inside of a bash script?

I have a problem replacing a command inside of a script, the offending line in the script looks like this: mail -s "$(hostname) on $(date)" It should be replaced with a line like this: nail -r "[email protected]" -s "Subject" -S smtp=255.255.255.255 But I can't get sed to do a replacement :) I wrote a small script for that purpose:...

replacing newline sed

How to replace \n from a line using sed command? ...

How can I delete duplicate lines in a file in Unix?

Is there way to delete duplicate lines in a file in Unix? I can to it with sort -u and uniq commands. but I want to use sed or awk. Is that possible? ...