Home > Archive > AWK > July 2004 > system function
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi all,
Using the system function system("mv " tmp file). It works, the file is
moved, but I receive the annoying error message
"Usage: mv [-dfirRv] file1 [file2 ...] target" ... after every file!
Any ideas how the error message can be avoided?
Chuck
| |
| Ulrich M. Schwarz 2004-07-19, 8:55 am |
| "Chuck" <chuckmg@acm.org> writes:
> Hi all,
>
> Using the system function system("mv " tmp file). It works, the file is
> moved, but I receive the annoying error message
> "Usage: mv [-dfirRv] file1 [file2 ...] target" ... after every file!
>
> Any ideas how the error message can be avoided?
You're missing an explicit space between tmp and file, I think. What
you're executing is "mv SRCdest" instead of "mv SRC dest".
Greetings
Ulrich
--
Mole problems? Call Avogadro's Pest Control, at (602) 257-1023!
-- DA
| |
| E. Rosten 2004-07-19, 8:55 am |
| Chuck wrote:
> Hi all,
>
> Using the system function system("mv " tmp file). It works, the file is
> moved, but I receive the annoying error message
> "Usage: mv [-dfirRv] file1 [file2 ...] target" ... after every file!
>
> Any ideas how the error message can be avoided?
Yes, you're concatenating tmp and file without putting a space in
between. Try:
"mv " tmp " " file
Here's a debugging hint. Try putting this in instead of system:
printf("%s\n", "mv " tmp file)
-Ed
| |
| Ian Stirling 2004-07-19, 3:55 pm |
| E. Rosten <look@my.sig> wrote:
> Chuck wrote:
>
> Yes, you're concatenating tmp and file without putting a space in
> between. Try:
>
> "mv " tmp " " file
>
>
> Here's a debugging hint. Try putting this in instead of system:
>
> printf("%s\n", "mv " tmp file)
>
Or even instead of
system("command"var)
system("echo command" var
| |
|
| Thanks guys,
You were right. The missing space between tmp and file was needed. In
fact, tmp is not a variable and needed to be within quotes. But I'm still
having problems!!! The relevant code is:
system("rm " fnm )
system("mv tmp " fnm)
where fnm is a variable containing the filename. When the prog is run, I
get the msg:
'mv: cannot rename "tmp" to "xx1": Access is denied.'
Have even tried closing fnm, getline, etc. before the statement in question
but no luck.
Need help again.
Chuck
"Ian Stirling" <root@mauve.demon.co.uk> wrote in message
news:40fbcf1e$0$196$ed2619ec@ptn-nntp-reader03.plus.net...
> E. Rosten <look@my.sig> wrote:
is[color=darkred]
> Or even instead of
> system("command"var)
> system("echo command" var
| |
| Ian Stirling 2004-07-19, 8:55 pm |
| Chuck <chuckmg@acm.org> wrote:
> Thanks guys,
>
> You were right. The missing space between tmp and file was needed. In
> fact, tmp is not a variable and needed to be within quotes. But I'm still
> having problems!!! The relevant code is:
>
> system("rm " fnm )
> system("mv tmp " fnm)
>
> where fnm is a variable containing the filename. When the prog is run, I
> get the msg:
> 'mv: cannot rename "tmp" to "xx1": Access is denied.'
> Have even tried closing fnm, getline, etc. before the statement in question
> but no luck.
Ok.
Replace system with print.
Now, try command from command-line, and see why it won't work.
| |
|
| you are doing "rm" and "mv" actions with a file that awk still has open (the
"getline" loop) - add a "close(fnm)" right after the while loop (and before the
first "system") to release the file.
--
pop is Mark
I'm lost. I've gone to look for myself.
If I should return before I get back, keep me here.
--
"Chuck" <chuckmg@acm.org> wrote in message
news:EC1Lc.102940$WX.1847@attbi_s51...
> Ed,
>
> 'mv tmp xx1' works fine from the command-line ... immediately after getting
> the error msg from the script.???
>
> Am attaching the whole script - it is very short - plus a test file.
> Perhaps there is something amiss with the MKS AWK program.???
>
> Thanks for your efforts.
>
> Chuck
>
> "Ian Stirling" <root@mauve.demon.co.uk> wrote in message
> news:40fc3bda$0$92640$ed2619ec@ptn-nntp-reader02.plus.net...
> still
> I
> question
>
>
>
| |
| E. Rosten 2004-07-20, 8:55 am |
| Chuck wrote:
> Ed,
>
> 'mv tmp xx1' works fine from the command-line ... immediately after getting
> the error msg from the script.???
>
> Am attaching the whole script - it is very short - plus a test file.
> Perhaps there is something amiss with the MKS AWK program.???
MKS awk? So you're using windows then, I assume. If that's the case,
then I don't know what the fix is, since Windows has issues with
moving/renaming/deleting files which are currently open. Under Linux
with gawk, it works fine. The solution might be to wrap it in a batch
file to perform the file manipulation operations.
On another note, it's a bit more convinient for reading to quote the
files inline for many people, since many silly programs (like mozilla
mail, for instance) requires an external program to view text files for
some reason.
-Ed
--
(You can't go wrong with psycho-rats.) (er258)(@)(eng.cam)(.ac.uk)
/d{def}def/f{/Times findfont s scalefont setfont}d/s{10}d/r{roll}d f 5/m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}
for /s 15 d f pop 240 420 m 0 1 3 { 4 2 1 r sub -1 r show } for showpage
| |
|
| oops - I just noticed that fnm is derived from FILENAME (so you must be running
"awk -f test.awk xx1.dat") - closing will not release it since awk still has it
open. Also, "tmp" is still open from the "print" statement. You will need to
change the logic so "system" calls are not working with open files. example:
BEGIN { FS = "\t"
fnm = FILENAME
}
FILENAME != fnm {
fnm = FILENAME
}
{
n=gsub(/\</, "<")
n=gsub(/\>/, ">")
print > "tmp"
}
END { close("tmp")
system("rm " fnm )
system("mv tmp " fnm)
system("echo mv tmp " fnm)
# printf("%s\n", "mv tmp " fnm)
}
--
pop is Mark
I'm lost. I've gone to look for myself.
If I should return before I get back, keep me here.
--
"pop" <p_o_p@hotmail.com> wrote in message
news:ME6Lc.10805$WP1.9910@fe1.texas.rr.com...
> you are doing "rm" and "mv" actions with a file that awk still has open (the
> "getline" loop) - add a "close(fnm)" right after the while loop (and before
the
> first "system") to release the file.
>
> --
> pop is Mark
> I'm lost. I've gone to look for myself.
> If I should return before I get back, keep me here.
> --
> "Chuck" <chuckmg@acm.org> wrote in message
> news:EC1Lc.102940$WX.1847@attbi_s51...
>
>
| |
|
| if you are working with multiple files; i.e. awk -f test.awk *.dat then the
logic could be:
BEGIN { FS = "\t"
for(i in ARGV) {
fnm=ARGV[i]
while ( getline < fnm >0) {
n=gsub(/\</, "<")
n=gsub(/\>/, ">")
print > "tmp"
}
close(fnm)
close("tmp")
system("rm " fnm )
system("mv tmp " fnm)
system("echo mv tmp " fnm)
# printf("%s\n", "mv tmp " fnm)
}
}
--
pop is Mark
I'm lost. I've gone to look for myself.
If I should return before I get back, keep me here.
--
"pop" <p_o_p@hotmail.com> wrote in message
news:m57Lc.10806$WP1.5868@fe1.texas.rr.com...
> oops - I just noticed that fnm is derived from FILENAME (so you must be
running
> "awk -f test.awk xx1.dat") - closing will not release it since awk still has
it
> open. Also, "tmp" is still open from the "print" statement. You will need to
> change the logic so "system" calls are not working with open files. example:
> BEGIN { FS = "\t"
> fnm = FILENAME
> }
>
> FILENAME != fnm {
> fnm = FILENAME
> }
>
> {
> n=gsub(/\</, "<")
> n=gsub(/\>/, ">")
> print > "tmp"
> }
> END { close("tmp")
> system("rm " fnm )
> system("mv tmp " fnm)
> system("echo mv tmp " fnm)
> # printf("%s\n", "mv tmp " fnm)
> }
> --
> "pop" <p_o_p@hotmail.com> wrote in message
> news:ME6Lc.10805$WP1.9910@fe1.texas.rr.com...
> the
>
| |
|
| if you are working with multiple files; i.e. awk -f test.awk *.dat then the
logic could be:
BEGIN { FS = "\t"
for(i in ARGV) {
fnm=ARGV[i]
while ( getline < fnm >0) {
n=gsub(/\</, "<")
n=gsub(/\>/, ">")
print > "tmp"
}
close(fnm)
close("tmp")
system("rm " fnm )
system("mv tmp " fnm)
system("echo mv tmp " fnm)
# printf("%s\n", "mv tmp " fnm)
}
}
--
pop is Mark
I'm lost. I've gone to look for myself.
If I should return before I get back, keep me here.
--
| |
|
| Hi Mark,
Thank loads. You certainly know your AWK/Windows. You were right on! Had
to make only a few minor mods to your code. Here is the final:
BEGIN { FS = "\t"
for(i=1; i < ARGC; i++) {
fnm=ARGV[i]
print i "fnm = " fnm
while ( getline < fnm >0) {
n=gsub(/\</, "<")
n=gsub(/\>/, ">")
print > "tmp"
}
close(fnm)
close("tmp")
system("rm " fnm )
system("mv tmp " fnm)
}
}
Will be happy to provide a cc-compilation for anyone who would like it and
doesn't have awk. It is of use for those using the Photoshop Web Photo
Gallery... specifically in formatting the captions. The latter will not
leave any embedded tags, <->, in peace. This code will return them.
Chuck
"pop" <p_o_p@hotmail.com> wrote in message
news:0A7Lc.10812$WP1.10046@fe1.texas.rr.com...
> if you are working with multiple files; i.e. awk -f test.awk *.dat then
the
> logic could be:
> BEGIN { FS = "\t"
> for(i in ARGV) {
> fnm=ARGV[i]
> while ( getline < fnm >0) {
> n=gsub(/\</, "<")
> n=gsub(/\>/, ">")
> print > "tmp"
> }
> close(fnm)
> close("tmp")
> system("rm " fnm )
> system("mv tmp " fnm)
> system("echo mv tmp " fnm)
> # printf("%s\n", "mv tmp " fnm)
> }
> }
> --
> pop is Mark
> I'm lost. I've gone to look for myself.
> If I should return before I get back, keep me here.
> --
>
>
| |
|
| Mark,
Sorry for the delayed response. Had already sent a msg but it obviously got
lost somewhere.
First of all, many, many thanks for showing me the way. With a few minor
mods, it worked!!! You're a wiz at awk/windows. My hat's off to you. The
final script is below.
Chuck
BEGIN { FS = "\t"
for(i=1; i < ARGC; i++) {
fnm=ARGV[i]
while ( getline < fnm >0) {
n=gsub(/\</, "<")
n=gsub(/\>/, ">")
print > "tmp"
}
close(fnm)
close("tmp")
system("rm " fnm )
system("mv tmp " fnm)
print fnm
}
}
| |
|
| you're welcome... Glad I could help... I have both of your responses on my
news-server. Sometimes servers drop a message after sending it on to the rest of
Usenet.
Glad I could help...
--
pop is Mark
Old age ain't no place for sissies.
--
"Chuck" <chuckmg@acm.org> wrote in message
news:UXVLc.163332$XM6.95239@attbi_s53...
> Mark,
>
> Sorry for the delayed response. Had already sent a msg but it obviously got
> lost somewhere.
>
> First of all, many, many thanks for showing me the way. With a few minor
> mods, it worked!!! You're a wiz at awk/windows. My hat's off to you. The
> final script is below.
>
> Chuck
>
> BEGIN { FS = "\t"
> for(i=1; i < ARGC; i++) {
> fnm=ARGV[i]
> while ( getline < fnm >0) {
> n=gsub(/\</, "<")
> n=gsub(/\>/, ">")
> print > "tmp"
> }
> close(fnm)
> close("tmp")
> system("rm " fnm )
> system("mv tmp " fnm)
> print fnm
> }
> }
>
>
|
|
|
|
|