LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-04-2013, 07:56 AM   #1
sumathi_subramaniam
LQ Newbie
 
Registered: Nov 2013
Posts: 3

Rep: Reputation: Disabled
awk file redirect issue


We have an issue with awk in linux.
We have a ${file2} present in a directory. When following command is executed ,it is creating overlapping files.

awk -F'|' '$22 <= 20131101 { print $0 }' ${file1} > ${file2}

Over lap file:
some content from $file1
some content from existing ${file2}
 
Old 11-04-2013, 08:04 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Can you be a bit more specific about your problem?

If I look at the above code, there doesn't seem to be anything wrong with it. A single > is used, so no appending is done.

${file1} holds the name of the input file, ${file2} holds the name of the output file. Have you checked the correctness of the actual file names?
 
Old 11-04-2013, 08:14 AM   #3
sumathi_subramaniam
LQ Newbie
 
Registered: Nov 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
But somehow appending is done even though only > is used . Not just clean appending ,it creates overlapped file.
File names looks good to me
 
Old 11-04-2013, 08:22 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
I just did the following test and I cannot reproduce your problem:
Code:
$ file1=input
$ file2=output
$ ls- l ${file1} ${file2}
ls: cannot access output: No such file or directory
-rw-r----- 1 druuna druuna 95 nov  4 14:19 input
$ cat ${file1}
1|2|3|20131030|5|6
1|2|3|20131031|5|6
1|2|3|20131101|5|6
1|2|3|20131102|5|6
1|2|3|20131103|5|6
$ awk -F'|' '$4 <= 20131101 { print $0 }' ${file1}  > ${file2}
$ cat ${file2}
1|2|3|20131030|5|6
1|2|3|20131031|5|6
1|2|3|20131101|5|6
$ awk -F'|' '$4 <= 20131101 { print $0 }' ${file1}  > ${file2}
$ cat ${file2}
1|2|3|20131030|5|6
1|2|3|20131031|5|6
1|2|3|20131101|5|6
Can you post a relevant part of the input and the resulting output?
 
Old 11-04-2013, 08:31 AM   #5
sumathi_subramaniam
LQ Newbie
 
Registered: Nov 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Me too unable to replicate outside the script.
This command is executed as a part of batch process,where ${file2} was previously created by first instances of the script.
When the second instance tries to overwrite the ${file2},it is getting corrupted
 
Old 11-04-2013, 08:39 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by sumathi_subramaniam View Post
Me too unable to replicate outside the script.
This command is executed as a part of batch process,where ${file2} was previously created by first instances of the script.
When the second instance tries to overwrite the ${file2},it is getting corrupted
If that is the case then the problem is not awk but something else in the script(s).

Without knowing how the script(s) is/are implemented and what code they contain it is impossible to help you.
 
Old 11-04-2013, 08:39 AM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
probably several scripts run in the same time and that causes corruption?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
running series of awk commands from an awk file oreka18 Programming 3 05-16-2012 02:13 AM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 11:49 AM
parsing a text file - to awk or not to awk ? rollyah Programming 9 08-18-2011 03:20 PM
how to pipe/redirect awk output into a variable? johnpaulodonnell Linux - Newbie 2 01-25-2007 07:54 AM
ip redirect issue loser122 Linux - Networking 1 09-30-2003 02:54 PM


All times are GMT -5. The time now is 10:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration