From: Hongyi Zhao on 1 Apr 2010 23:23 Hi all, I use the following code to obtain the lines existing file2 but not in file1, and then store the results into file2 as follows: awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' file1 file2 > file2 I've a question about the above operation: does the file2 will be exposed to read/write conflict issue in this case? In detail, when we redirect the result into file2, it also as the input file for the awk's manipulation. Any hints on this issue? -- ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
From: Hermann Peifer on 2 Apr 2010 04:17 Hongyi Zhao wrote: > Hi all, > > I use the following code to obtain the lines existing file2 but not in > file1, and then store the results into file2 as follows: > > awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' file1 file2 > file2 > > I've a question about the above operation: does the file2 will be > exposed to read/write conflict issue in this case? Trying this out with some test files would have taken you less time than posting the question to a newsgroup. Hermann
From: Chris F.A. Johnson on 2 Apr 2010 04:36 On 2010-04-02, Hongyi Zhao wrote: > Hi all, > > I use the following code to obtain the lines existing file2 but not in > file1, and then store the results into file2 as follows: > > awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' file1 file2 > file2 > > I've a question about the above operation: does the file2 will be > exposed to read/write conflict issue in this case? In detail, when we > redirect the result into file2, it also as the input file for the > awk's manipulation. '> file2' erases file2 before awk can read it. -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== ===== and is released under the GNU General Public Licence =====
From: Hongyi Zhao on 2 Apr 2010 07:51 On 2 Apr 2010 08:36:22 GMT, "Chris F.A. Johnson" <cfajohnson(a)gmail.com> wrote: > '> file2' erases file2 before awk can read it. Thanks a lot, but I find the following strange things: 1- If do the the following things: $ echo aa > file1 $ echo bb > file2 $ awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' file1 file2 bb $ awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' file1 file2 > file2 $ cat file2 In this case, file2 will be empty in the end, i.e., '> file2' erases file2 before awk can read it. 2- If do the the following things: $ echo aa > file1 $ echo bb > file2 $ awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' file1 file2 bb $ awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' file1 file2 | sort -u > file2 $ cat file2 bb This time, the operation will be finished successfully. Any hints on this issue? -- ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
From: pk on 2 Apr 2010 07:50 Hongyi Zhao wrote: > 2- If do the the following things: > > $ echo aa > file1 > $ echo bb > file2 > $ awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' file1 file2 > bb > > $ awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' file1 file2 | sort -u > file2 > $ cat file2 > bb > > This time, the operation will be finished successfully. > > Any hints on this issue? Luck.
|
Next
|
Last
Pages: 1 2 3 4 Prev: AWK - Stop processing Next: bash: how to transfer some non-ascii code |