problem with redirection in cat and sed
5 posters
Re: problem with redirection in cat and sed
cat littlefile
Marry had a little lamb.little lamb.little lamb
Mary had a little lamb whose fleece was white as snow
Every where that marywent,mary went,mary went.Everywhere that mary went
[@oracleclient ~]$ cat littlefile | sed -e 's/mary/naaz/g'
Marry had a little lamb.little lamb.little lamb
Mary had a little lamb whose fleece was white as snow
Every where that naazwent,naaz went,naaz went.Everywhere that naaz went
[@oracleclient ~]$ cat littlefile | sed -e 's/mary/naaz/g' > littlefile
[@oracleclient ~]$ cat littlefile
[@oracleclient ~]$
[@oracleclient ~]$ cat littlefile | sed -e 's/mary/naaz/g' > littlej
[@oracleclient ~]$ cat littlej
[@oracleclient ~]$
Marry had a little lamb.little lamb.little lamb
Mary had a little lamb whose fleece was white as snow
Every where that marywent,mary went,mary went.Everywhere that mary went
[@oracleclient ~]$ cat littlefile | sed -e 's/mary/naaz/g'
Marry had a little lamb.little lamb.little lamb
Mary had a little lamb whose fleece was white as snow
Every where that naazwent,naaz went,naaz went.Everywhere that naaz went
[@oracleclient ~]$ cat littlefile | sed -e 's/mary/naaz/g' > littlefile
[@oracleclient ~]$ cat littlefile
[@oracleclient ~]$
[@oracleclient ~]$ cat littlefile | sed -e 's/mary/naaz/g' > littlej
[@oracleclient ~]$ cat littlej
[@oracleclient ~]$
SakeenaHarris- Posts : 7
Points : 13
Join date : 2010-03-08
Re: problem with redirection in cat and sed
in the $ cat littlefile | sed -e 's/mary/naaz/g' > littlefile command
first the littlefile is opened in write mode first ! so all the content gets cleared!
so the sed command takes an empty file as the input and so it produces a empty output!
so u get an empty file at-last!
first the littlefile is opened in write mode first ! so all the content gets cleared!
so the sed command takes an empty file as the input and so it produces a empty output!
so u get an empty file at-last!
Re: problem with redirection in cat and sed
try this command
$ ls -l >abc
i mean create a file (abc) which does not exist already!
then open the file abc and see! u will see that abc is present in there !
it means first the output file is created and then the ls command is executed!
$ ls -l >abc
i mean create a file (abc) which does not exist already!
then open the file abc and see! u will see that abc is present in there !
it means first the output file is created and then the ls command is executed!
Re: problem with redirection in cat and sed
mightyganesh wrote:in the $ cat littlefile | sed -e 's/mary/naaz/g' > littlefile command
first the littlefile is opened in write mode first ! so all the content gets cleared!
so the sed command takes an empty file as the input and so it produces a empty output!
so u get an empty file at-last!
And since the littlefile is already empty, in the second attempt using littlej, the output is empty.
[335920@oracleclient Srinath]$ cat>littlefile
Sometext
Second Line.
[335920@oracleclient Srinath]$ cat littlefile | sed -e 's/Some/some/g' > little
[335920@oracleclient Srinath]$ cat little
sometext
Second Line.
itssrinath- Posts : 4
Points : 5
Join date : 2010-02-26
Re: problem with redirection in cat and sed
if u want to store the output of sed in same file, go for '<<'. this ll append the output of sed command to the input file.
DineshThangaraju- Posts : 18
Points : 19
Join date : 2010-02-26
Age : 35
Location : India
DineshThangaraju- Posts : 18
Points : 19
Join date : 2010-02-26
Age : 35
Location : India
Re: problem with redirection in cat and sed
still if u want to do it, use temp file.
it will store the output of sed command in the same file.
- Code:
$ sed 's/PINK/BLUE/g' 1.txt > 1.temp ; cat 1.temp > 1.txt ; rm 1.temp
it will store the output of sed command in the same file.
Permissions in this forum:
You cannot reply to topics in this forum
|
|