Newsgroups: comp.unix.shell
From: Geoff Clare <ge...@clare.See-My-Signature.invalid>
Date: Thu, 11 Oct 2012 13:33:17 +0100
Local: Thurs, Oct 11 2012 8:33 am
Subject: Re: A strange issue when using awk to substitute a field in specific line.
Hongyi Zhao wrote:
Because you are using 1<>file to redirect standard output, the shell
> $ cat sub_test.awk > baseDirForScriptSelf="$(cd "$(dirname "$0")"; pwd)" > awk -v a=$baseDirForScriptSelf '{if($1=="set" && $2=="base_path") sub(/ > ^.*$/,a"/apt-mirror",$3);print}' ./for_test 1<>./for_test > But, after I run the sub_test.awk, I found that the for_test file become > $ cat for_test > As you can see, the final for_test becomes four lines in it. The last > $ ./sub_test.awk
> I cann't figure out why this should happen. Could you please give me does not truncate the file before executing awk. When awk writes to the file it is overwriting existing data. Your transformation shortens the data, and therefore there is some of the old data left at the end when awk has finished writing the new data. The 1<>file trick is neat, but it should only really be used when
An example of a safe usage is:
$ cat for_test
-- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||