Re: Re: need help with sed problem
i agree with that - the underscore that was used is also valid. you might look at proper quoting of variables to avoid this. something like cat text.txt | sed -e 's/bbb.*/:$PWD/' new.txt The output from that, given Joao's original text.txt, is :$PWD The reason is that and $ have no special effect inside ''. I would prefer to use some other character for the s command delimiter as earlier posters in this thread suggested, because it is easier to read. But another way you can do it is to escape all the backslashes in $PWD using a shell expansion: $ sed s/.*/:${PWD//\//\\/}/ text.txt :/home/clive/temp You can see its effect on the string passed to sed using set -x: $ (set -x; sed s/.*/:${PWD//\//\\/}/ text.txt) + sed 's/.*/:\/home\/clive\/temp/' text.txt A brief explanation of ${PWD//\//\\/} :- ${PWD//A/B} replaces all occurrences of pattern A with string B. For A use \/ - the \ prevents / being treated as a delimiter. For B use \\/ - the first \ causes the second \ to be taken literally. I hope this helps. -- Cheers, Clive -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20110319144616.ga3...@rimmer.esmertec.com
need help with sed problem
Hello all I need to use sed to replace a given line in a text file with the current working directory. But this is getting quite tricky. Problem ilustrated below: $ cat text.txt :/some/wrong/path/ $ sed s/.*/:$TERM/ text.txt :xterm jmf@squeeje:~$ sed s/.*/:$PWD/ text.txt sed: -e expression #1, char 16: unknown option to `s' = I'd like to have :/home/myself Can anyone help ? thanks in advance. Joao -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/1300470364.2932.5.ca...@squeeje.critical.pt
Re: need help with sed problem
On Fri, 18 Mar 2011 17:46:04 + Joao Ferreira gmail joao.miguel.c.ferre...@gmail.com wrote: jmf@squeeje:~$ sed s/.*/:$PWD/ text.txt sed: -e expression #1, char 16: unknown option to `s' Hello, this is because $PWD gets expanded by shell before sed gets called, so what actually gets executed is: sed s/bbb.*/:/home/myself/ text.txt ...which is obviously syntactically incorrect. To get result you want, try using different separator character than /, for example the comma, or underscore: $ sed s,bbb.*,:$PWD, text.txt $ sed s_bbb.*_:$PWD_ text.txt -- Andrej Kacian -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20110318185908.2f959df8@penny
Re: need help with sed problem
On 2011-03-18 12:59:08 Andrej Kacian wrote: To get result you want, try using different separator character than /, for example the comma, or underscore: Colon is also a pretty good choice. While it is allowed in pathnames, it already causes problems. Try adding a directory containing colon to your PATH or MANPATH. :P -- Boyd Stephen Smith Jr. ,= ,-_-. =. b...@iguanasuicide.net ((_/)o o(\_)) ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-' http://iguanasuicide.net/\_/ signature.asc Description: This is a digitally signed message part.
Re: need help with sed problem
On Fri, 2011-03-18 at 18:59 +0100, Andrej Kacian wrote: On Fri, 18 Mar 2011 17:46:04 + Joao Ferreira gmail joao.miguel.c.ferre...@gmail.com wrote: jmf@squeeje:~$ sed s/.*/:$PWD/ text.txt sed: -e expression #1, char 16: unknown option to `s' Hello, this is because $PWD gets expanded by shell before sed gets called, so what actually gets executed is: sed s/bbb.*/:/home/myself/ text.txt ...which is obviously syntactically incorrect. To get result you want, try using different separator character than /, for example the comma, or underscore: $ sed s,bbb.*,:$PWD, text.txt $ sed s_bbb.*_:$PWD_ text.txt Thanks a lot... I did not know that was possible... I used the # separator. Worked just fine Thank you Joao -- Andrej Kacian -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/1300475305.2285.0.ca...@squeeje.critical.pt
Re: need help with sed problem
on 19:08 Fri 18 Mar, Joao Ferreira gmail (joao.miguel.c.ferre...@gmail.com) wrote: On Fri, 2011-03-18 at 18:59 +0100, Andrej Kacian wrote: On Fri, 18 Mar 2011 17:46:04 + Joao Ferreira gmail joao.miguel.c.ferre...@gmail.com wrote: jmf@squeeje:~$ sed s/.*/:$PWD/ text.txt sed: -e expression #1, char 16: unknown option to `s' Hello, this is because $PWD gets expanded by shell before sed gets called, so what actually gets executed is: sed s/bbb.*/:/home/myself/ text.txt ...which is obviously syntactically incorrect. To get result you want, try using different separator character than /, for example the comma, or underscore: $ sed s,bbb.*,:$PWD, text.txt $ sed s_bbb.*_:$PWD_ text.txt Thanks a lot... I did not know that was possible... I used the # separator. Worked just fine Please note that '#' is a valid filesystem name character. There are relatively few values which are safely excludable. In your case this shouldn't be a problem, but in the general case (I'm working on a script that needs to do path parsing) it's a bit of a pain. -- Dr. Ed Morbius, Chief Scientist /| Robot Wrangler / Staff Psychologist| When you seek unlimited power Krell Power Systems Unlimited| Go to Krell! -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20110318230526.gk3...@altaira.krellpowersys.exo
Re: need help with sed problem
On Fri, Mar 18, 2011 at 7:05 PM, Dr. Ed Morbius dredmorb...@gmail.comwrote: on 19:08 Fri 18 Mar, Joao Ferreira gmail (joao.miguel.c.ferre...@gmail.com) wrote: On Fri, 2011-03-18 at 18:59 +0100, Andrej Kacian wrote: On Fri, 18 Mar 2011 17:46:04 + Joao Ferreira gmail joao.miguel.c.ferre...@gmail.com wrote: Please note that '#' is a valid filesystem name character. There are relatively few values which are safely excludable. In your case this shouldn't be a problem, but in the general case (I'm working on a script that needs to do path parsing) it's a bit of a pain. i agree with that - the underscore that was used is also valid. you might look at proper quoting of variables to avoid this. something like cat text.txt | sed -e 's/bbb.*/:$PWD/' new.txt
find -execdir + sed problem
I'm trying to fix the file suffix on some file in my directories using sed and find but for some reason sed doesn't match the string in this manner, that is running find . -name *.JPG.jpg -execdir echo `echo '{}' | sed -e 's/\(.*\).JPG.jpg/\1.jpg/' -` \; on a directory with 2005_10_09-03_05_11.JPG.jpg prints 2005_10_09-03_05_11.JPG.jpg instead of 2005_10_09-03_05_11.jpg any idea what I'm doing wrong? find . -type f -exec echo `echo '{}' | tr [:upper:] [:lower:]` \; also fails to convert the file to lower case for some reason (same problem, doesn't change the case, as if it doesn't see the characters). Thanks -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Re: find -execdir + sed problem
On 2009-01-08 11:03 +0100, Micha Feigin wrote: I'm trying to fix the file suffix on some file in my directories using sed and find but for some reason sed doesn't match the string in this manner, that is running find . -name *.JPG.jpg -execdir echo `echo '{}' | sed -e 's/\(.*\).JPG.jpg/\1.jpg/' -` \; on a directory with 2005_10_09-03_05_11.JPG.jpg prints 2005_10_09-03_05_11.JPG.jpg instead of 2005_10_09-03_05_11.jpg any idea what I'm doing wrong? The shell does the process substitution before find even sees it: `echo '{}' | sed -e 's/\(.*\).JPG.jpg/\1.jpg/' -` is substituted by its output, which is {}, so you are effectively running find . -name *.JPG.jpg -execdir echo {} \; which is not what you intended. find . -type f -exec echo `echo '{}' | tr [:upper:] [:lower:]` \; also fails to convert the file to lower case for some reason (same problem, doesn't change the case, as if it doesn't see the characters). It does indeed not see them, it only sees {}. Sven -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Re: find -execdir + sed problem
On Thu, Jan 08, 2009 at 12:03:38 +0200, Micha Feigin (mi...@post.tau.ac.il) wrote: find . -type f -exec echo `echo '{}' | tr [:upper:] [:lower:]` \; also fails to convert the file to lower case for some reason (same problem, doesn't change the case, as if it doesn't see the characters). find . -type f | xargs rename y/A-Z/a-z/ -- Bob Cox. Stoke Gifford, near Bristol, UK. Please reply to the list only. Do NOT send copies directly to me. Debian on the NSLU2: http://bobcox.com/slug/ -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Re: find -execdir + sed problem
On Thu, Jan 08, 2009 at 12:03:38 +0200, Micha Feigin (mi...@post.tau.ac.il) wrote: I'm trying to fix the file suffix on some file in my directories using sed and find but for some reason sed doesn't match the string in this manner, that is running find . -name *.JPG.jpg -execdir echo `echo '{}' | sed -e 's/\(.*\).JPG.jpg/\1.jpg/' -` \; find . -type f | xargs rename s/JPG\.jpg/jpg/ -- Bob Cox. Stoke Gifford, near Bristol, UK. Please reply to the list only. Do NOT send copies directly to me. Debian on the NSLU2: http://bobcox.com/slug/ -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Re: find -execdir + sed problem
Bob Cox schrieb: On Thu, Jan 08, 2009 at 12:03:38 +0200, Micha Feigin (mi...@post.tau.ac.il) wrote: find . -type f -exec echo `echo '{}' | tr [:upper:] [:lower:]` \; also fails to convert the file to lower case for some reason (same problem, doesn't change the case, as if it doesn't see the characters). find . -type f | xargs rename y/A-Z/a-z/ If you have file names with special characters in it, e.g. blank characters, better use: find . -type f -print0| xargs -0 rename y/A-Z/a-z/ or find . -type f | while read FILE;do rename y/A-Z/a-z/ $FILE;done -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Re: find -execdir + sed problem
On Thu, 08 Jan 2009 11:24:27 +0100 Sven Joachim svenj...@gmx.de wrote: On 2009-01-08 11:03 +0100, Micha Feigin wrote: I'm trying to fix the file suffix on some file in my directories using sed and find but for some reason sed doesn't match the string in this manner, that is running find . -name *.JPG.jpg -execdir echo `echo '{}' | sed -e 's/\(.*\).JPG.jpg/\1.jpg/' -` \; on a directory with 2005_10_09-03_05_11.JPG.jpg prints 2005_10_09-03_05_11.JPG.jpg instead of 2005_10_09-03_05_11.jpg any idea what I'm doing wrong? The shell does the process substitution before find even sees it: `echo '{}' | sed -e 's/\(.*\).JPG.jpg/\1.jpg/' -` is substituted by its output, which is {}, so you are effectively running find . -name *.JPG.jpg -execdir echo {} \; which is not what you intended. find . -type f -exec echo `echo '{}' | tr [:upper:] [:lower:]` \; also fails to convert the file to lower case for some reason (same problem, doesn't change the case, as if it doesn't see the characters). It does indeed not see them, it only sees {}. doing find . -type f -exec echo '{}' | tr [:upper:] [:lower:] \; gives the expected output on the other hand find . -type f -exec echo `echo '{}' | tr [:upper:] [:lower:]` \; doesn't so trying to execute the command and output it to echo fails. Seems like I'm not clear on the substitution rules in this case Sven -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Re: find -execdir + sed problem
On Thu, Jan 08, 2009 at 12:03:38PM +0200, Micha Feigin wrote: I'm trying to fix the file suffix on some file in my directories using sed and find but for some reason sed doesn't match the string in this manner, that is running find . -name *.JPG.jpg -execdir echo `echo '{}' | sed -e 's/\(.*\).JPG.jpg/\1.jpg/' -` \; on a directory with 2005_10_09-03_05_11.JPG.jpg prints 2005_10_09-03_05_11.JPG.jpg instead of 2005_10_09-03_05_11.jpg any idea what I'm doing wrong? find . -type f -exec echo `echo '{}' | tr [:upper:] [:lower:]` \; I think you will find `echo '{}' | tr [:upper:] [:lower:]` is being executed by the shell before it executes find also fails to convert the file to lower case for some reason (same problem, doesn't change the case, as if it doesn't see the characters). Thanks -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org -- We got the best workforce in America�in the world. - George W. Bush 12/02/2005 Washington, DC signature.asc Description: Digital signature
Re: sed Problem die 2.
Hi, Ich muß eine Nummer aus folgendem String extrahieren: wenn du viele solche Sachen machen musst, lohnt sich für dich vielleicht ein Blick auf Perl! zB: --- extract.pl --- #!/usr/bin/perl while() { if ( m/\(([\d\/\-]+)\)/ ) { print $1; print \n; } } Und dann: $ ./extract.pl file - Moritz
Re: sed Problem die 2.
Am Mi 07.09.2005 11:38 schrieb Moritz Karbach [EMAIL PROTECTED]: Hallo, Ich muß eine Nummer aus folgendem String extrahieren: wenn du viele solche Sachen machen musst, lohnt sich für dich vielleicht ein Blick auf Perl! --- extract.pl --- #!/usr/bin/perl while() { if ( m/(([d/-]+))/ ) { print $1; print ; } } Und dann: $ ./extract.pl file Danke für deine Hilfe. Ich habe es zwischenzeitlich mit einem Bash-Skript gemacht. Habe schon viel gutes über Perl gehört allerdings habe ich im Moment nicht die Zeit noch eine weitere Sprache zu lernen. Danke! Viele Grüße Sven
sed Problem die 2.
Hallo zusammen, nachdem ihr mir beim letzten sed-Problem geholfen habt und alles soweit funktioniert habe ich nun ein weiteres das ich mit dem Wissen des 1. leider nicht alleine hin bekomme. Ich weiß nicht ob es mit sed überhaubt funktioniert. Ich muß eine Nummer aus folgendem String extrahieren: 381 470 M (@# )[92 50 25 0]xS 573 470 M (0621/48293-91)[50 50 50 50 28 50 50 50 50 50 33 50 0]xS 1184 470 M ( #@)[25 50 0]xS Die Nummer die ich daraus brauche ist die 0621/48293-91. Der gesamte String ist natürlich lang und die gesuchte Nummer steht immer zwischen dem (@# ) ... und dem ... ( #@) Allerdings kommen zwischen den Einleitung- und Ausleitungs- Zeilen noch verschiedene Zeichen die durch PS-Treiber erzeugt werden. In Worte formuliert würde es lauten: Nimm alle Zeichen zwischen (@# ) und ( #@). Suche innerhalb dieses Teilstrings nach einer Klammer (..). Der Inhalt in dieser Klammer ist die gesuchte Nummer im Rohformat die ich mit den sed Befehlen aus dem ersten Beispiel wieder aufbereiten kann. Ist soetwas mit sed möglich? Viele Grüße Sven
Re: sed Problem die 2.
* Sven Gehr [EMAIL PROTECTED] [050906 09:56]: Ich muß eine Nummer aus folgendem String extrahieren: 381 470 M (@# )[92 50 25 0]xS 573 470 M (0621/48293-91)[50 50 50 50 28 50 50 50 50 50 33 50 0]xS 1184 470 M ( #@)[25 50 0]xS Die Nummer die ich daraus brauche ist die 0621/48293-91. [...] In Worte formuliert würde es lauten: Nimm alle Zeichen zwischen (@# ) und ( #@). Suche innerhalb dieses ^ Das da ist kein normales Space-Zeichen sondern ein Hard Space (0xa0). Soll das wirklich so sein, oder ist das ein Lapsus deines Editors? Teilstrings nach einer Klammer (..). Der Inhalt in dieser Klammer ist die gesuchte Nummer im Rohformat die ich mit den sed Befehlen aus dem ersten Beispiel wieder aufbereiten kann. Ich habe das erste Beispiel zwar nicht verfolgt, aber ich würde das Problem in etwa so lösen: sed '/(@# )/,/( #@)/s/.*(\([-/0-9]*\)).*/\1/;t;d' file Dabei habe ich angenommen, dass der Hard Space in Wirklichkeit ein normales Space darstellen soll und dass die gesuchten Nummern nur Zahlen und die Zeichen / und - enthalten dürfen. Beste Grüße - Jürgen -- GPG A997BA7A | 87FC DA31 5F00 C885 0DC3 E28F BD0D 4B33 A997 BA7A signature.asc Description: Digital signature
Re: sed - Problem
Am Mi 31.08.2005 15:27 schrieb Frank Küster [EMAIL PROTECTED]: Michelle Konzack [EMAIL PROTECTED] wrote: Am 2005-08-31 12:55:18, schrieb Sven Gehr: Hallo zusammen, bin auf ein weiteres Problem mit meinem Skript (sed) gestoßen welches absolut komisch ist, zumindest für mich. Ausgangsmaterial ist eine Postscript-Datei. Wenn ich diese mit: ps2ascii out.ps out.txt in ASCII konvertieren enthält diese: - @# 06214829391 #@ Hallo Fax, ich bin's der Faxmeister. ^L%%[Page: 1]%% %%[LastPage]%% - wenn ich anschliesend mein Skript: #!/bin/sh # txt2number PS2ASCII=/usr/bin/ps2ascii TEMPFILE=/usr/lib/cups/backend/out.txt FAXFILECONTEND=$(cat $TEMPFILE) FAXNUM=`echo $FAXFILECONTEND|sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g'` echo $FAXNUM darauf anwende erhalte ich die Ausgabe: 06214829391 also alles perfekt. Nun muß ich die zwei Schritte zu einem zusammenfassen und habe folgendes Skript erstellt: #!/bin/sh PS2ASCII=/usr/bin/ps2ascii FAXFILE=/usr/lib/cups/backend/out.ps FAXNUM=`($PS2ASCII $FAXFILE)|sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g'` echo $FAXNUM wenn ich dieses nun auf die gleiche Ausgangs-Datei (out.ps) anwende erhalte ich als Ausgabe: %%[ProductName:ESPGhostscript]%% @#06214829391 %%[Page:1]%% %%[LastPage]%% Ich finde absolut keinen Fehler. als kleiner Hinweis, dieses PS-File wurde von einem Windows-Druckertreiber erzeugt. Wenn ich das PS-File vom Linux-Druckertreiber erzeugen lasse funktioniert auch das 2. Skript was die Nummer extrahiert. Ich versteh's einfach nicht. Viele Grüße Sven
Re: sed - Problem
Am 2005-09-01 10:03:02, schrieb Sven Gehr: also alles perfekt. Nun muß ich die zwei Schritte zu einem zusammenfassen und habe folgendes Skript erstellt: #!/bin/sh PS2ASCII=/usr/bin/ps2ascii FAXFILE=/usr/lib/cups/backend/out.ps FAXNUM=`($PS2ASCII $FAXFILE)|sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ FAXNUM=`$PS2ASCII $FAXFILE |sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ ^^^ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g'` echo $FAXNUM Viele Grüße Sven Greetings Michelle -- Linux-User #280138 with the Linux Counter, http://counter.li.org/ Michelle Konzack Apt. 917 ICQ #328449886 50, rue de Soultz MSM LinuxMichi 0033/3/8845235667100 Strasbourg/France IRC #Debian (irc.icq.com) signature.pgp Description: Digital signature
Re: sed - Problem
Am Do 01.09.2005 11:06 schrieb Michelle Konzack [EMAIL PROTECTED]: Am 2005-09-01 10:03:02, schrieb Sven Gehr: also alles perfekt. Nun muß ich die zwei Schritte zu einem zusammenfassen und habe folgendes Skript erstellt: #!/bin/sh PS2ASCII=/usr/bin/ps2ascii FAXFILE=/usr/lib/cups/backend/out.ps FAXNUM=`($PS2ASCII $FAXFILE)|sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ FAXNUM=`$PS2ASCII $FAXFILE |sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ ^^^ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 'sg' -e 's/-//g'` echo $FAXNUM hat leider nichts gebracht. Nochimmer die gleiche, falsche Ausgabe: @# 06214829391 #@ Hallo Fax, ich bin's der Faxmeister. ^L%%[Page: 1]%% %%[LastPage]%% -
Re: sed - Problem
Hallo, Am Thu, 01 Sep 2005, Sven Gehr schrieb: Am Mi 31.08.2005 15:27 schrieb Frank Küster [EMAIL PROTECTED]: Michelle Konzack [EMAIL PROTECTED] wrote: Am 2005-08-31 12:55:18, schrieb Sven Gehr: [..] also alles perfekt. Nun muß ich die zwei Schritte zu einem zusammenfassen und habe folgendes Skript erstellt: #!/bin/sh PS2ASCII=/usr/bin/ps2ascii FAXFILE=/usr/lib/cups/backend/out.ps FAXNUM=`($PS2ASCII $FAXFILE)|sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ ^ ^ die subshell ist ueberfluessig. //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g'` echo $FAXNUM wenn ich dieses nun auf die gleiche Ausgangs-Datei (out.ps) anwende erhalte ich als Ausgabe: %%[ProductName:ESPGhostscript]%% @#06214829391 %%[Page:1]%% %%[LastPage]%% Ich finde absolut keinen Fehler. als kleiner Hinweis, dieses PS-File wurde von einem Windows-Druckertreiber erzeugt. AHA! Les bitte meine anderen Antworten (speziell die in suse-linux). FAXNUM=`${PS2ASCII} \$FAXFILE\ | tr '\r' '\n' | \ sed 's/^@@ *+/00/;s/[^0-9]\+//g;'` Das sollte so eigentlich funktionieren -- kann aber sein, dass das mit dem Zeilenende ersetzen nicht gleich korrekt funktioniert, und dass dann die Verankerung der '@@' nicht funktioniert. Achso, du verwendest ja inzwichen @# und #@ (ueberfluessigerweise). Also ggfs. mal folgendes testen: FAXNUM=`${PS2ASCII} \$FAXFILE\ | tr '\r' '\n' | \ sed 's/@# *+/00/;s/[^0-9]\+//g;'` Falls das zuviel erwischt, schau dir meine anderen Mails nochmal genauer an. Spontan mit deinen geaenderten Anforderungen wuerde ich auch noch folgendes probieren (ungetestet!): FAXNUM=`${PS2ASCII} \$FAXFILE\ | tr '\r' '\n' | \ sed '/@#.*#@/ { s/.*\(@[EMAIL PROTECTED]).*/\1/; s/[EMAIL PROTECTED] *+/00/; s/[^0-9]\+//g; }'` Hm. Wie sieht das PS denn konkret aus? Kannst du da mal ein Beispiel der relevanten Stelle mailen? Ich denke, das PS2ASCII ist ueberfluessig und die Nummer laesst sich direkt aus dem PS rauslesen. BTW: awk waere speziell dann ueberlegenswert (ungetestet!): FAXNUM=`awk ' BEGIN { RS=[\r\n]; ## nimmt \r und \n und \r\n als Zeileumbruch, aber ## ungetestet, ersetzt also das 'tr'. } /@#.*#@/ { $0 = gensub(/[EMAIL PROTECTED](.*)[EMAIL PROTECTED]/, \\1, 0); sub(/^ *\+ */, 00, $0); print gensub(/[^0-9]/, , g); }' \$FAXFILE\` HTH, -dnh -- Treat your password like your toothbrush. Don't let anybody else use it, and get a new one every six months. -- Clifford Stoll [found in ssl_engine_pphrase.c] -- Haeufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
sed - Problem
Hallo zusammen, ich habe ein Problem mit sed. Die Problemstellung ist wie folgt: In einem Textfile stehen an einer nicht exakt definierten Position ein String der mit @@ beginnt und mit @@ endet. Der Teil der zwischen diesen @@'s steht soll extrahiert werden und unformatiert werden. Beim umfarmatieren sollen folgende Regeln angewendet werden: 1.) Ein führendes + Zeichen soll durch 00 ersetzt werden. Das soll lediglich mit einem + Zeichen passieren das ganz am Anfang steht. Tauch dieses Zeichen innerhalb des Strings nocheinmal auf wird es wie ein Sonderzeichen behandelt und entfernt (siehe unten). Zu beachten ist. Das zwichem dem + und den @@-Zeichen die den Anfang markieren durchaus ein Leerzeichen stehen kann. Die Zeichenkette kann also wie folgt beginnen: @@+ @@ + 2.) Nachdem ein evtl. vorhandenes + Zeichen am Anfang umgesetzt ist sollen alle Zeichen die keine Zahl sind (Leerzeichen, /, - etc.) entfernt werden. Ich bin nicht unbedingt der sed-Profi. Was ich bisher hinbekommen habe ist: sed -r 's/@@\s*?\+([0-9]+)\s*?([0-9]+)[^0-9]*?([0-9]+)\/?([0-9]+)?@@/00\1\2\3\4/g' Diese Syntax enthält jedoch noch Fehler und ich bekomm's einfach nicht hin. Das mit @@ gekennzeichnete Ende wird nicht erkannt: Mache ich ein: echo @@+49621 4829/399@@bla bla bla|sed . erhalte ich: 00496214829399bla bla bla Selbst wenn ich hinter der 2. @@-Kette keine Zeichen mehr übergebe ibt es Varianten die nicht funktionieren: @@+49621/4829-399@@ - @@+49621/4829-399@@ @@+49621/4829 399@@ - @@+49621/4829 399@@ Kenn sich jemand mit sed aus und kann mir sagen wo mein Fehler ist? Viele Grüße Sven
Re: sed - Problem
Sven Gehr [EMAIL PROTECTED] wrote: 2.) Nachdem ein evtl. vorhandenes + Zeichen am Anfang umgesetzt ist sollen alle Zeichen die keine Zahl sind (Leerzeichen, /, - etc.) entfernt werden. Ich bin nicht unbedingt der sed-Profi. Was ich bisher hinbekommen habe ist: sed -r 's/@@\s*?\+([0-9]+)\s*?([0-9]+)[^0-9]*?([0-9]+)\/?([0-9]+)?@@/00\1\2\3\4/g' Diese Syntax enthält jedoch noch Fehler und ich bekomm's einfach nicht hin. Das mit @@ gekennzeichnete Ende wird nicht erkannt: Mache ich ein: echo @@+49621 4829/399@@bla bla bla|sed . erhalte ich: 00496214829399bla bla bla Hilft dir echo etwas davor @@+49621 4829/399@@bla bla bla|sed 's/.*\(@@.*@@\).*/\1/g' weiter? Für das Löschen der Sonderzeichen würde ich nicht sed, sondern tr nehmen. Gruß, Frank -- Frank Küster Inst. f. Biochemie der Univ. Zürich Debian Developer
Re: sed - Problem
Am Mittwoch 31 August 2005 09:41 schrieb Sven Gehr: [sed-Wunsch] echo @@+49621 4829/399@@bla bla bla|sed . erhalte ich: 00496214829399bla bla bla Also wenn nichts gegen mehrere Ausdrücke spricht probier doch mal: 's/.*@@([EMAIL PROTECTED])@@.*/\1/g' 's/\s*+/00/' 's/[^0-9]//g' also z.B. mit sed -r -e 's/.*@@([EMAIL PROTECTED])@@.*/\1/g' -e 's/\s*+/00/' -e 's/[^0-9]//g' Das tut hier. Gruß Chris -- A: because it distrupts the normal process of thought Q: why is top posting frowned upon
Re: sed - Problem
Am 2005-08-31 09:41:13, schrieb Sven Gehr: Hallo zusammen, ich habe ein Problem mit sed. Die Problemstellung ist wie folgt: blubber sed -r 's/@@\s*?\+([0-9]+)\s*?([0-9]+)[^0-9]*?([0-9]+)\/?([0-9]+)?@@/00\1\2\3\4/g' Mache ich ein: echo @@+49621 4829/399@@bla bla bla|sed . erhalte ich: 00496214829399bla bla bla Kenn sich jemand mit sed aus und kann mir sagen wo mein Fehler ist? wie währe es mit: echo @@+49621 4829/399@@bla bla bla |sed -r 's/@@\s*?\+([0-9]+)\s*?([0-9]+)[^0-9]*?([0-9]+)\/?([0-9]+)?@@.*/00\1\2\3\4/g' Da kriegste dann 00496214829399 Viele Grüße Sven Greetings Michelle -- Linux-User #280138 with the Linux Counter, http://counter.li.org/ Michelle Konzack Apt. 917 ICQ #328449886 50, rue de Soultz MSM LinuxMichi 0033/3/8845235667100 Strasbourg/France IRC #Debian (irc.icq.com) signature.pgp Description: Digital signature
Re: sed - Problem
Am 2005-08-31 11:23:33, schrieb Christian Frommeyer: Also wenn nichts gegen mehrere Ausdrücke spricht probier doch mal: 's/.*@@([EMAIL PROTECTED])@@.*/\1/g' 's/\s*+/00/' 's/[^0-9]//g' also z.B. mit sed -r -e 's/.*@@([EMAIL PROTECTED])@@.*/\1/g' -e 's/\s*+/00/' -e 's/[^0-9]//g' Das ist aber nicht gut... Besser: sed -r -e 's/.*@@([EMAIL PROTECTED])@@.*/\1/g;s/\s*+/00/;s/[^0-9]//g' Greetings Michelle -- Linux-User #280138 with the Linux Counter, http://counter.li.org/ Michelle Konzack Apt. 917 ICQ #328449886 50, rue de Soultz MSM LinuxMichi 0033/3/8845235667100 Strasbourg/France IRC #Debian (irc.icq.com) signature.pgp Description: Digital signature
Re: sed - Problem
Michelle Konzack [EMAIL PROTECTED] wrote: Am 2005-08-31 11:23:33, schrieb Christian Frommeyer: sed -r -e 's/.*@@([EMAIL PROTECTED])@@.*/\1/g' -e 's/\s*+/00/' -e 's/[^0-9]//g' Das ist aber nicht gut... Besser: sed -r -e 's/.*@@([EMAIL PROTECTED])@@.*/\1/g;s/\s*+/00/;s/[^0-9]//g' Rein interessehalber... Warum ist das nicht gut? Gibts da irgendwelche Unterschiede zwischen beiden Varianten? regards Mario -- Uebrigens... Wer frueher stirbt ist laenger tot! -- Haeufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
Re: sed - Problem
On Wednesday 31 August 2005 09:41, Sven Gehr wrote: Hallo zusammen, ich habe ein Problem mit sed. Die Problemstellung ist wie folgt: In einem Textfile stehen an einer nicht exakt definierten Position ein String der mit @@ beginnt und mit @@ endet. Der Teil der zwischen diesen @@'s steht soll extrahiert werden und unformatiert werden. Beim umfarmatieren sollen folgende Regeln angewendet werden: 1.) Ein führendes + Zeichen soll durch 00 ersetzt werden. Das soll lediglich mit einem + Zeichen passieren das ganz am Anfang steht. Tauch dieses Zeichen innerhalb des Strings nocheinmal auf wird es wie ein Sonderzeichen behandelt und entfernt (siehe unten). Zu beachten ist. Das zwichem dem + und den @@-Zeichen die den Anfang markieren durchaus ein Leerzeichen stehen kann. Die Zeichenkette kann also wie folgt beginnen: @@+ @@ + Das macht z.B. sed -e 's/\([^,]*\)+/\100/' sedtest spuckt aus: @@00 @@ 00 [^,] soll heißen: alles außer einem Komma, also z.B. @ In dem Stil kannst du dann weiter machen Eilige Grüße geb Viele Grüße Sven -- Haeufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
Re: sed - Problem
Am 2005-08-31 11:52:03, schrieb Mario 'BitKoenig' Holbe: Michelle Konzack [EMAIL PROTECTED] wrote: Am 2005-08-31 11:23:33, schrieb Christian Frommeyer: sed -r -e 's/.*@@([EMAIL PROTECTED])@@.*/\1/g' -e 's/\s*+/00/' -e 's/[^0-9]//g' Das ist aber nicht gut... Besser: sed -r -e 's/.*@@([EMAIL PROTECTED])@@.*/\1/g;s/\s*+/00/;s/[^0-9]//g' Rein interessehalber... Warum ist das nicht gut? Gibts da irgendwelche Unterschiede zwischen beiden Varianten? -e spannt jedesmal einen neune einen editor Du kannst aber alle aktionen Zeile für Zeile in eine Datei schreiben und sed mit sed --script-file datei aufrufen und sed arbeitet dann eine Zeile nach der anderen ab. Auf der Commandline, wird das dann so angegeben wie ich es gemacht habe, also -e first;second;third;... jede Aktion also mit ; getrennt. regards Mario Greetings Michelle -- Linux-User #280138 with the Linux Counter, http://counter.li.org/ Michelle Konzack Apt. 917 ICQ #328449886 50, rue de Soultz MSM LinuxMichi 0033/3/8845235667100 Strasbourg/France IRC #Debian (irc.icq.com) signature.pgp Description: Digital signature
Re: sed - Problem
Am Mi 31.08.2005 11:26 schrieb Michelle Konzack [EMAIL PROTECTED]: Am 2005-08-31 09:41:13, schrieb Sven Gehr: Vielen Dank für die Vorschläge. In der zwischenzeit habe ich viel mit sed herum probiert und habe noch einiges geändert. Die Zeichen die den Anfang und das Ende markieren kann ich ja selbst steuern da diese durch die Aplikation in das File geschrieben werden. Ich hielt es für besser wenn ich für Anfang und Ende nicht die gleichen nehme sonder unterschiedliche: @# - markiert den Anfang # @ - markiert das Ende Mit: echo bla bla @# +49 621 / 4829-399 #@ bla bla |sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g' erhalte ich dann: 06214829399 Das einzigste was bei der Lösung nicht funktioniert ist eine Prüfung auf weiter Sonderzeichen, Buchstaben etc. Das wäre jedoch in anbetracht des Verwendungszwecks nicht tragisch. Bei den Zahlen handelt es sich, wie sich der ein oder andere bestimmt schon gedacht hat, um Faxnummern. Diese werden aus unsere Datenbank eingemischt. Wenn da Buchstaben oder Sondernzeichen enthalten sind stimmt die Nummer ja ohnehin nicht und braucht auch nicht weiter verarbeitet zu werden. Nun wollte ich das Ganze in ein Skript einbauen und habe so meine Probleme damit. #!/bin/sh FAXFILE=/usr/lib/cups/backend/doc155.txt FAXNUME=$FAXFILE|sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g' echo $FAXNUM In der Datei doc155.txt steht genau die Zeichenkette drin wie ich sie die ganze Zeit mit echo... übergeben habe. Wenn ich das Skript ausführe wird jedoch nichts ausgegeben. Wie muß ich das zuweisen? Viele Grüße Sven
Re: sed - Problem
Am Mi 31.08.2005 12:55 schrieb Sven Gehr [EMAIL PROTECTED]: Hallo, [...] Nun wollte ich das Ganze in ein Skript einbauen und habe so meine Probleme damit. #!/bin/sh FAXFILE=/usr/lib/cups/backend/doc155.txt FAXNUME=$FAXFILE|sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 'sg' -e 's/-//g' echo $FAXNUM In der Datei doc155.txt steht genau die Zeichenkette drin wie ich sie die ganze Zeit mit echo... übergeben habe. Wenn ich das Skript ausführe wird jedoch nichts ausgegeben. Wie muß ich das zuweisen? hab's heraus gefunden. Viele Grüße Sven
Re: sed - Problem
Am 2005-08-31 12:55:18, schrieb Sven Gehr: Nun wollte ich das Ganze in ein Skript einbauen und habe so meine Probleme damit. #!/bin/sh FAXFILE=/usr/lib/cups/backend/doc155.txt FAXNUME=$FAXFILE|sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g' echo $FAXNUM Probiers mal mit: FAXNUME=`cat $FAXFILE |sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g'` Greetings Michelle -- Linux-User #280138 with the Linux Counter, http://counter.li.org/ Michelle Konzack Apt. 917 ICQ #328449886 50, rue de Soultz MSM LinuxMichi 0033/3/8845235667100 Strasbourg/France IRC #Debian (irc.icq.com) signature.pgp Description: Digital signature
Re: sed - Problem
On 31.Aug 2005 - 14:18:00, Michelle Konzack wrote: Am 2005-08-31 12:55:18, schrieb Sven Gehr: Nun wollte ich das Ganze in ein Skript einbauen und habe so meine Probleme damit. #!/bin/sh FAXFILE=/usr/lib/cups/backend/doc155.txt FAXNUME=$FAXFILE|sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g' echo $FAXNUM Probiers mal mit: FAXNUME=`cat $FAXFILE |sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g'` Michelle, das haette ich von dir nicht erwartet - useless use of cat, sed ... $FAXFILE oder sed ... $FAXFILE funktioniert ebenso und beansprucht einen Prozess weniger. Andreas -- You are wise, witty, and wonderful, but you spend too much time reading this sort of trash. -- Haeufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
Re: sed - Problem
Michelle Konzack [EMAIL PROTECTED] wrote: Am 2005-08-31 12:55:18, schrieb Sven Gehr: Nun wollte ich das Ganze in ein Skript einbauen und habe so meine Probleme damit. #!/bin/sh FAXFILE=/usr/lib/cups/backend/doc155.txt FAXNUME=$FAXFILE|sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g' echo $FAXNUM Probiers mal mit: FAXNUME=`cat $FAXFILE |sed -e 's/[EMAIL PROTECTED]//' -e 's/[EMAIL PROTECTED]//' -e 's/ //g' -e 's/^+49/0/' -e 's/^+/00/' -e 's/\///g' -e 's/-//g'` Useless use of cat sed -e ' ... ' $FAXFILE Und wenn man mal ein Kommando hat, dass seine Eingaben nur von stdin annimmt und nicht aus einer Datei lesen kann, ist commando --parameter ... $FAXFILE immer noch besser. Gruß, Frank -- Frank Küster Inst. f. Biochemie der Univ. Zürich Debian Developer
Re: sed - Problem
Hallo, Am Wed, 31 Aug 2005, Michelle Konzack schrieb: Am 2005-08-31 11:52:03, schrieb Mario 'BitKoenig' Holbe: Michelle Konzack [EMAIL PROTECTED] wrote: Am 2005-08-31 11:23:33, schrieb Christian Frommeyer: sed -r -e 's/.*@@([EMAIL PROTECTED])@@.*/\1/g' -e 's/\s*+/00/' -e 's/[^0-9]//g' Das ist aber nicht gut... Besser: sed -r -e 's/.*@@([EMAIL PROTECTED])@@.*/\1/g;s/\s*+/00/;s/[^0-9]//g' Ist '-r' portabel? $ zgrep -- '\-r' `man -w sed` and the bug-reporting address, After the address (or address-range), executed if the address (or address-range) does Rein interessehalber... Warum ist das nicht gut? Gibts da irgendwelche Unterschiede zwischen beiden Varianten? -e spannt jedesmal einen neune einen editor Was? Du kannst aber alle aktionen Zeile für Zeile in eine Datei schreiben und sed mit sed --script-file datei $ sed --script-file /dev/null sed: unrecognized option `--script-file' [...] 'sed -f' oder bei GNU-sed: 'sed --file' Es geht uebrigens auch: ,[ delemptylines ] | #!/usr/bin/sed -f | /^[[:space:]]*$/d ` Noch nen 'chmod u+x' hinterher und feddich. Praktisch hinter einem 'cpp' (oder 'gcc -E') ohne '-o'. $ echo -e '#include linux/version.h\nUTS_RELEASE\n' \ | gcc -E - | delemptylines aufrufen und sed arbeitet dann eine Zeile nach der anderen ab. Auf der Commandline, wird das dann so angegeben wie ich es gemacht habe, also -e first;second;third;... jede Aktion also mit ; getrennt. Oder durch einen Zeilenumbruch. Genau wie in einem sed-script. $ seq 1 9 | sed -n '1 { s/1/X/ p } 5p' X 5 HTH HAND, -dnh -- When I woke up this morning, the cat was barfing on me. Things have gone downhill since then. -- Michel Buijsman -- Haeufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
Re: sed problem
On Mon, Oct 20, 2003 at 10:09:47PM +0100, Dave selby wrote: I need to get the contents of a HTML title tag put it in a string. ie titlespecialist cards/title I need the specialist cards in a variable $titlecontents I thought it would be easy with sed sed -n '/title/,/\/title/p' sed -n 's/title\(.*\)\/title/\1/gp' would be my most general solution floris -- Debian GNU/Linux -- The power of freedom www.debian.org | www.gnu.org | www.kernel.org -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: sed problem
Dave selby wrote: I need to get the contents of a HTML title tag put it in a string. ie titlespecialist cards/title I need the specialist cards in a variable $titlecontents I thought it would be easy with sed sed -n '/title/,/\/title/p' But no go. I have tried various ways but to no avail. Any ideas ? Dave I got all your e-mails, many thanks. I will try them out ... Dave -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
sed problem
I need to get the contents of a HTML title tag put it in a string. ie titlespecialist cards/title I need the specialist cards in a variable $titlecontents I thought it would be easy with sed sed -n '/title/,/\/title/p' But no go. I have tried various ways but to no avail. Any ideas ? Dave -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: sed problem
On Sun, Oct 19, 2003 at 11:37:44AM +0100, Dave selby wrote: I need to get the contents of a HTML title tag put it in a string. ie titlespecialist cards/title I need the specialist cards in a variable $titlecontents I thought it would be easy with sed sed -n '/title/,/\/title/p' But no go. I have tried various ways but to no avail. Any ideas ? I'm sure this is not the pukka way to do it but for jim in html_file_directory/*; do grep \title\ $jim | sed 's/.*title//' | sed 's/\/title.*//'; done file_list.txt puts all the titles from the scripts in html_file_directory into file_list.txt. Dave -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: sed problem
On Sun, 19 Oct 2003 11:37:44 +0100, Dave selby wrote: I need to get the contents of a HTML title tag put it in a string. ie titlespecialist cards/title I need the specialist cards in a variable $titlecontents I thought it would be easy with sed sed -n '/title/,/\/title/p' But no go. I have tried various ways but to no avail. Any ideas ? Dave Try: sed 's#title\(.*\)/title#\1#' Greetigs Andre -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: sed problem
Dave selby [EMAIL PROTECTED] [2003:10:19:11:37:44+0100] scribed: I need to get the contents of a HTML title tag put it in a string. ie titlespecialist cards/title I need the specialist cards in a variable $titlecontents I thought it would be easy with sed sed -n '/title/,/\/title/p' But no go. I have tried various ways but to no avail. Which of these best meets your loosely described needs? sed -n '/^title[^]*\/title/p' sed -n '/\/*title/p' sed -n 's!/*title!!gp' hth -- Best Regards, mds mds resource 877.596.8237 - Dare to fix things before they break . . . - Our capacity for understanding is inversely proportional to how much we think we know. The more I know, the more I know I don't know . . . -- pgp0.pgp Description: PGP signature
Re: sed problem
On Sun, Oct 19, 2003 at 11:37:44AM +0100, Dave selby wrote: I need to get the contents of a HTML title tag put it in a string. ie titlespecialist cards/title I need the specialist cards in a variable $titlecontents I thought it would be easy with sed sed -n '/title/,/\/title/p' But no go. I have tried various ways but to no avail. Any ideas ? In perl: #!/usr/bin/perl while() { s/title//; s/\/title//; print; } or in a one-liner: perl -e 'while(){s/title//;s/\/title//;print;}' or using the -n option to make the while(){} implicit: perl -ne 's/title//;s/\title//;print;' or using the -p option that also makes the print implicit (like sed: perl -pe 's/title//;s/\/title;' Hope that helps, Bijan -- Bijan Soleymani [EMAIL PROTECTED] http://www.crasseux.com signature.asc Description: Digital signature
OT: Makefile sed-Problem
Dear all, although I know it isn't anything that directly refers to Debian, I dare to post since I have seen many similar questions. Please excuse! The Problem: from a friend, I receive text-files that have a lot of whitespace before the end of a line or even lines consisting of only whitespace. For this reason, I set up a Makefile that would remove all whitespaces: ## receive: cat in_file \ | sed -e 's/\s*$$//' \ new_in_file ## I expect this to remove all whitespaces '\s*'ending a line. But, funny enough, it removes all 's' ending a line. This has been driving me mad for a couple of hours that's why I dare to post. What's wrong with 's/\s*$$//' in a Makefile? I tried 's/\\s*$$//' -- with no success. Hopefully someone immediately sees the problem and can give me any hint. Thanks in advance, wbr, Lukas -- Lukas Ruf | Wanna know anything about raw | http://www.lpr.ch | IP? http://www.rawip.org | -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: OT: Makefile sed-Problem
On Mon, 2003-10-06 at 12:31, Lukas Ruf wrote: Dear all, although I know it isn't anything that directly refers to Debian, I dare to post since I have seen many similar questions. Please excuse! It's not off topic for debian-user. The Problem: from a friend, I receive text-files that have a lot of whitespace before the end of a line or even lines consisting of only whitespace. For this reason, I set up a Makefile that would remove all whitespaces: ## receive: cat in_file \ | sed -e 's/\s*$$//' \ new_in_file ## I expect this to remove all whitespaces '\s*'ending a line. But, funny enough, it removes all 's' ending a line. This has been driving me mad for a couple of hours that's why I dare to post. What's wrong with 's/\s*$$//' in a Makefile? I tried 's/\\s*$$//' -- with no success. Hopefully someone immediately sees the problem and can give me any hint. You are trying to use a Perl regular expression with sed; that doesn't work. Although the sed manpage refers to perlre, sed does not seem to support Perl regular expressions. You should look at man 7 regexp instead. Try: sed -r -e 's/[[:space:]]+$$//' NB, you don't need to do cat in_file | sed [pattern]; you can do sed [pattern] in_file -- Oliver Elphick[EMAIL PROTECTED] Isle of Wight, UK http://www.lfix.co.uk/oliver GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C Blessed is the man that walketh not in the counsel of the ungodly, nor standeth in the way of sinners, nor sitteth in the seat of the scornful. But his delight is in the law of the LORD; and in his law doth he meditate day and night. Psalms 1:1,2 -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: OT: Makefile sed-Problem
Oliver Elphick [EMAIL PROTECTED] [2003-10-06 14:09]: On Mon, 2003-10-06 at 12:31, Lukas Ruf wrote: You are trying to use a Perl regular expression with sed; that doesn't work. Although the sed manpage refers to perlre, sed does not seem to support Perl regular expressions. You should look at man 7 regexp instead. ok, didn't know this. Thanks! Try: sed -r -e 's/[[:space:]]+$$//' Thanks this worked as expected! wbr, Lukas -- Lukas Ruf | Wanna know anything about raw | http://www.lpr.ch | IP? http://www.rawip.org | -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: SED problem
Michael D Schleif wrote: Michael D Schleif [EMAIL PROTECTED] [2003:10:04:16:32:37-0500] scribed: Dave selby [EMAIL PROTECTED] [2003:10:04:19:25:32+0100] scribed: I have multiple html files. I need to remove the same chunk of code from all of them. I have made a bash loop to feed the files to sed, but am struggling with the sed code. I need to delete all the code between !-- lockon:a:1 -- and !-- lockoff -- Including the above comments. Do you want to specify a range like this: sed '/!-- lockon:a:1/,/!-- lockoff/d' /tmp/tmp.txt Oops! I forgot about the closing the lockoff comment: # sed -f /tmp/tmp.sed /tmp/tmp.txt # cat /tmp/tmp.sed /!-- lockon:a:1/,/!-- lockoff/{ N /--/d D } Many thanks, it works great ... just playing with it to get how it works ! Dave -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: SED problem
Bijan Soleymani wrote: On Sat, Oct 04, 2003 at 07:25:32PM +0100, Dave selby wrote: I have multiple html files. I need to remove the same chunk of code from all of them. I have made a bash loop to feed the files to sed, but am struggling with the sed code. I need to delete all the code between !-- lockon:a:1 -- and !-- lockoff -- Including the above comments. I have tried, played with N, d substitution to // but can't pattern match across multiple lines. Any ideas ? You can handle that sort of thing in perl pretty easily. The syntax is pretty similar and the performance is about the same. However you get to use variables, conditions, loops, etc. Bijan ...mmm... perl, I have heard of it but not played with it yet. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Further SED problem
Im may be trying to push SED to far, in which case perl has been suggested, but here is my problem ... For a series of html pages, I need to take the text from the title tag and insert it where there is a xx in the document, deleting the xx. Ie use a template, fill in the title let SED do the hard work. My best guess so far is /title/,//title/h to get the text into hold space, then I hit a problem, s will not accept the hold space as a replacement string c\ is a block command I have looked at h,H,g,G but I still need a substitution. Any ideas, or is it hello perl ? Dave 4 !-- lockon:a:3: 5 -- 6 titleSpecialist cards/title 7 meta name=keywords content= 8 specialist cards, cards, photograph, card, photographs, personalised, design !-- lockon:a:4: 31 -- 32 xx 33 86 div class=botlinkOrder a href=order.htmlxx/a/div 87 88 !-- lockoff by ...br 33 !-- lockoff 34 -- etc . -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
SED problem
I have multiple html files. I need to remove the same chunk of code from all of them. I have made a bash loop to feed the files to sed, but am struggling with the sed code. I need to delete all the code between !-- lockon:a:1 -- and !-- lockoff -- Including the above comments. I have tried, played with N, d substitution to // but can't pattern match across multiple lines. Any ideas ? Dave In the HTML I have the following img src=pngs/whkeepsakebanner.png title= keepsake cards, designers of personalised cards alt= keepsake cards, designers of personalised cardsbr /td /tr !-- lockon:a:1: -- tr td class=toplinksa href=index.htmlHome/a nbsp;nbsp;nbsp;nbsp;nbsp; a href=aboutus.htmlAbout us/a nbsp;nbsp;nbsp;nbsp;nbsp; a href=gallery.htmlGallery/a nbsp;nbsp;nbsp;nbsp;nbsp; a href=order.htmlOrder cards/a nbsp;nbsp;nbsp;nbsp;nbsp; a href=pricing.htmlPricing/a nbsp;nbsp;nbsp;nbsp;nbsp; a href=contactus.htmlContact us/abr a href=faq.htmlFAQ/a nbsp;nbsp;nbsp;nbsp;nbsp; a href= sitemap.htmlSite map/a nbsp;nbsp;nbsp;nbsp;nbsp; a href= links.htmlSpecialist Links/a nbsp;nbsp;nbsp;nbsp;nbsp; a href=reciplinks.htmlReciprocal Links/a/td /tr !-- lockoff -- !-- lockon:a:2: -- -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: SED problem
On Sat, Oct 04, 2003 at 07:25:32PM +0100, Dave selby wrote: I have multiple html files. I need to remove the same chunk of code from all of them. I have made a bash loop to feed the files to sed, but am struggling with the sed code. I need to delete all the code between !-- lockon:a:1 -- and !-- lockoff -- Including the above comments. I have tried, played with N, d substitution to // but can't pattern match across multiple lines. Any ideas ? You can handle that sort of thing in perl pretty easily. The syntax is pretty similar and the performance is about the same. However you get to use variables, conditions, loops, etc. Bijan -- Bijan Soleymani [EMAIL PROTECTED] http://www.crasseux.com signature.asc Description: Digital signature
Re: SED problem
Dave selby [EMAIL PROTECTED] [2003:10:04:19:25:32+0100] scribed: I have multiple html files. I need to remove the same chunk of code from all of them. I have made a bash loop to feed the files to sed, but am struggling with the sed code. I need to delete all the code between !-- lockon:a:1 -- and !-- lockoff -- Including the above comments. Do you want to specify a range like this: sed '/!-- lockon:a:1/,/!-- lockoff/d' /tmp/tmp.txt hth -- Best Regards, mds mds resource 877.596.8237 - Dare to fix things before they break . . . - Our capacity for understanding is inversely proportional to how much we think we know. The more I know, the more I know I don't know . . . -- pgp0.pgp Description: PGP signature
Re: SED problem
Michael D Schleif [EMAIL PROTECTED] [2003:10:04:16:32:37-0500] scribed: Dave selby [EMAIL PROTECTED] [2003:10:04:19:25:32+0100] scribed: I have multiple html files. I need to remove the same chunk of code from all of them. I have made a bash loop to feed the files to sed, but am struggling with the sed code. I need to delete all the code between !-- lockon:a:1 -- and !-- lockoff -- Including the above comments. Do you want to specify a range like this: sed '/!-- lockon:a:1/,/!-- lockoff/d' /tmp/tmp.txt Oops! I forgot about the closing the lockoff comment: # sed -f /tmp/tmp.sed /tmp/tmp.txt # cat /tmp/tmp.sed /!-- lockon:a:1/,/!-- lockoff/{ N /--/d D } -- Best Regards, mds mds resource 877.596.8237 - Dare to fix things before they break . . . - Our capacity for understanding is inversely proportional to how much we think we know. The more I know, the more I know I don't know . . . -- pgp0.pgp Description: PGP signature
Re: sed problem
Hallo Andre, Am 21:46 2002-12-17 +0100 hat Andre Fischer geschrieben: hallöchen, ich glaub mein sed kann nicht mehr zählen :( ich möchte die Zahlenfolge 12345 durch PLZ ersetzen und habe folgenden Test gemacht: echo test 12345 test | sed s/[0-9]\{5\}/PLZ/g und habe folgendes Ergebnis erwartet: test PLZ test leider kommt test 12345 test - was mach ich da falsch? Die beispiele im Buch basieren soviel ich weis auf /bin/tcsh. Wenn du /bin/bash verwendest, must Du den String in Hochkommas setzen, also: echo test 12345 test | sed 's/[0-9]\{5\}/PLZ/g' ^ ^ hierund hier tschau fisch Bis ein anderes mal Michelle -- Häufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
sed problem
hallöchen, ich glaub mein sed kann nicht mehr zählen :( ich möchte die Zahlenfolge 12345 durch PLZ ersetzen und habe folgenden Test gemacht: echo test 12345 test | sed s/[0-9]\{5\}/PLZ/g und habe folgendes Ergebnis erwartet: test PLZ test leider kommt test 12345 test - was mach ich da falsch? tschau fisch -- Häufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
Re: sed problem
On Tue, Dec 17, 2002 at 09:46:30PM +0100, Andre Fischer wrote: ich glaub mein sed kann nicht mehr zählen :( ich möchte die Zahlenfolge 12345 durch PLZ ersetzen und habe folgenden Test gemacht: echo test 12345 test | sed s/[0-9]\{5\}/PLZ/g wenn ich mich recht erinnere, kann sed nicht den Multiplikator, er kann hier wirklich nicht zählen :) Bei mir geht echo test 12345 test | sed s/[0-9][0-9][0-9][0-9][0-9]/PLZ/g Wolfgang -- Häufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
Re: sed problem
Am Dienstag, 17. Dezember 2002 22:08 schrieb Wolfgang Erig: On Tue, Dec 17, 2002 at 09:46:30PM +0100, Andre Fischer wrote: ich glaub mein sed kann nicht mehr zählen :( ich möchte die Zahlenfolge 12345 durch PLZ ersetzen und habe folgenden Test gemacht: echo test 12345 test | sed s/[0-9]\{5\}/PLZ/g wenn ich mich recht erinnere, kann sed nicht den Multiplikator, er kann hier wirklich nicht zählen :) Bei mir geht echo test 12345 test | sed s/[0-9][0-9][0-9][0-9][0-9]/PLZ/g laut Linux in a Nutshell solls aber gehn :( ich brauche letztendlich folgendes: irgendwas TRENNZEICHEN12345 irgendwas anderesTRENNZEICHEN -irgendwas TRENNZEICHEN12345TRENNZEICHENirgendwas anderesTRENNZEICHEN wobei hier 12345 für eine PLZ steht und das ganze auf eine Textdatei angewendet werden muß Wolfgang -- Häufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
Re: sed problem
Hallo, Andre Fischer [EMAIL PROTECTED]: echo test 12345 test | sed s/[0-9]\{5\}/PLZ/g und habe folgendes Ergebnis erwartet: test PLZ test leider kommt test 12345 test - was mach ich da falsch? Deine Shell verschluckt die Backslashes. Probiere es mal mit echo test 12345 test | sed 's/[0-9]\{5\}/PLZ/g' Gruß, Harald -- Harald Weidner [EMAIL PROTECTED] -- Häufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
Re: sed problem
Andreas Wodrich wrote: fisch wrote: Am Dienstag, 17. Dezember 2002 22:08 schrieb Wolfgang Erig: On Tue, Dec 17, 2002 at 09:46:30PM +0100, Andre Fischer wrote: ich glaub mein sed kann nicht mehr zählen :( ich möchte die Zahlenfolge 12345 durch PLZ ersetzen und habe folgenden Test gemacht: echo test 12345 test | sed s/[0-9]\{5\}/PLZ/g wenn ich mich recht erinnere, kann sed nicht den Multiplikator, er kann hier wirklich nicht zählen :) Bei mir geht echo test 12345 test | sed s/[0-9][0-9][0-9][0-9][0-9]/PLZ/g laut Linux in a Nutshell solls aber gehn :( ich brauche letztendlich folgendes: irgendwas TRENNZEICHEN12345 irgendwas anderesTRENNZEICHEN -irgendwas TRENNZEICHEN12345TRENNZEICHENirgendwas anderesTRENNZEICHEN wobei hier 12345 für eine PLZ steht und das ganze auf eine Textdatei angewendet werden muß Wolfgang Soweit ich es aus der Docu zu sed herauslese, kann s/../../ nicht als Parameter uebergeben werden. Ich hatte leider nicht weit genug gelesen: man sed: ... If no -e,-f,--expression, or --file options are given on the command- line, then the first non-option argument on the command line is taken to be the script to be executed. ... Aber das script unten funktioniert (;-). Es muss eine Datei angelegt werden, in der dieser Befehl abgelegt wird. z.B vi sedscript eine Zeile mit s/[0-9]\{5\}/PLZ/g einfuegen, abspeichern. echo test 12345 test | sed -f sedscript liefert: test PLZ test Gruss Andreas -- Häufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)
Re: sed problem
Am Dienstag, 17. Dezember 2002 22:50 schrieb [EMAIL PROTECTED]: Andre Fischer schrieb: ich möchte die Zahlenfolge 12345 durch PLZ ersetzen und habe folgenden Test gemacht: echo test 12345 test | sed s/[0-9]\{5\}/PLZ/g und habe folgendes Ergebnis erwartet: test PLZ test leider kommt test 12345 test - was mach ich da falsch? $ echo test 12345 test | sed s/[0-9]\{5\}/PLZ/g test 12345 test $ echo test 12345 test | sed 's/[0-9]\{5\}/PLZ/g' test PLZ test Vor dem sed hängt noch die bash, vermute ich. Nebenbei: um der bash ein TAB für (z.B.) sed mitzuteilen, hilft Strg-v TABTaste. Durch fehlende '' und ggf. der TAB-Geschichte kann man sich eine ganze Weile ergebnislos mit dem sed amüsieren. danke das wars, nicht sed sondern bash warn schuld :) tschau fisch -- Häufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject unsubscribe. Probleme? Mail an [EMAIL PROTECTED] (engl)