sed 'wasauchimmer' a > a

Post Reply
Message
Author
dwax
Posts: 65
Joined: 14. Jun 2001 15:30

sed 'wasauchimmer' a > a

#1 Post by dwax »

Hallo Zusammen,
wieso macht dieser kleine Befehl meine Datei a 0 Byte groß?
sed 'wasauchimmer' a > a
Eigentlich müßte sed doch a auchlesen, den Inhalt in die stdout schreiben und die Bash a dann aus stdout wieder füllen, oder?

MfG Dirk

User avatar
hjb
Pro-Linux
Posts: 3264
Joined: 15. Aug 1999 16:59
Location: Bruchsal
Contact:

Re: sed 'wasauchimmer' a > a

#2 Post by hjb »

Hi!

> a wird zuerst ausgeführt. Was eigentlich auch logisch ist, denn es wird von der Shell ausgeführt, die dann erst sed aufrufen kann. Verwende "sed -i"

Gruß,
hjb
Pro-Linux - warum durch Fenster steigen, wenn es eine Tür gibt?

User avatar
Sauerlaender
Posts: 34
Joined: 11. Apr 2003 12:57
Location: Sauerland

Re: sed 'wasauchimmer' a > a

#3 Post by Sauerlaender »

Hi Dirk!

<blockquote><hr>
wieso macht dieser kleine Befehl meine Datei a 0 Byte groß?
sed 'wasauchimmer' a > a
Eigentlich müßte sed doch a auchlesen, den Inhalt in die stdout schreiben und die Bash a dann aus stdout wieder füllen, oder?
<hr></blockquote>

Nein, als erstes sorgt die Umleitung dafür, daß eine leere Datei "a" angelegt wird. Anschließend will der sed die Datei "a" auslesen und das Ergebnis nach "a" schreiben. Da "a" aber bereits neu initialisiert wurde, gibt's da nichts mehr zu lesen...

Einzige mir bekannte Lösung:

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
sed 'wasauchimmer' a > a.tmp
mv a.tmp a
</font><hr></pre></blockquote>
Gruss vom
Sauerlaender

dwax
Posts: 65
Joined: 14. Jun 2001 15:30

Re: sed 'wasauchimmer' a > a

#4 Post by dwax »

@hjb
Auf die Idee die Manpage zu fragen, hätte ich auch kommen können ...
Danke!

@Sauerlaender
Das war auch immer mein Workaround <img src="http://www.pl-forum.de/UltraBoard/Images/Wilk.gif" border="0" align="middle">
Aber jetzt haben wir beide was gelernt.

User avatar
Sauerlaender
Posts: 34
Joined: 11. Apr 2003 12:57
Location: Sauerland

Re: sed 'wasauchimmer' a > a

#5 Post by Sauerlaender »

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
cdr@dedul001:~> sed --version
GNU sed version 3.02

Copyright (C) 1998 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

cdr@dedul001:~> sed -i
sed: invalid option -- i
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--help display this help and exit
-V, --version output version information and exit

If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.

E-mail bug reports to: bug-gnu-utils@gnu.org .
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
</font><hr></pre></blockquote>

Hmmm...
Gruss vom
Sauerlaender

dwax
Posts: 65
Joined: 14. Jun 2001 15:30

Re: sed 'wasauchimmer' a > a

#6 Post by dwax »

# sed -V
GNU sed version 4.0.7
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.


# sed --help
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
-i[suffix], --in-place[=suffix]
edit files in place (makes backup if extension supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
-r, --regexp-extended
use extended regular expressions in the script.
-s, --separate
consider files as separate rather than as a single continuous
long stream.
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
--help display this help and exit
-V, --version output version information and exit

If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.

E-mail bug reports to: bonzini@gnu.org .
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.


Time to update ...

MfG Dirk

Zorro

Re: sed 'wasauchimmer' a > a

#7 Post by Zorro »

Hi Sauerlaender!


*** hjb schrieb:

> a wird zuerst ausgeführt. Was eigentlich auch logisch ist, denn es wird
von der Shell ausgeführt, die dann erst sed aufrufen kann. Verwende ...


*** Da hast Du nicht zu widersprechen:

Nein, als erstes sorgt die Umleitung dafür, daß eine leere Datei "a" angelegt wird. Anschließend ...


*** Wieso `Nein.'? Ist doch selbiges.

Post Reply