How to make this code working?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make this code working?
# 1  
Old 10-08-2013
How to make this code working?

Hi Gurus,

I wrote a simple code, but it doesn't work, can body help me to fix the issue.

Code:
awk -F',' 'BEGIN{n=0}{
NR == FNR {fname[$1];next}
{
if ($3==fname)
n=1
}
END{if n==0}
}' tmpsrc srcfile.txt

Thanks in advance
# 2  
Old 10-08-2013
You cannot expect us to discover a broken program's intended purpose. We can't see what it's supposed to be doing if you don't explain.

What is it supposed to be doing?

In what way does it 'not work'?

What data are you using it with?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 10-08-2013
Quote:
Originally Posted by Corona688
You cannot expect us to discover a broken program's intended purpose. We can't see what it's supposed to be doing if you don't explain.

What is it supposed to be doing?

In what way does it 'not work'?

What data are you using it with?
Thanks for your reply.

I am going to update the explaination.
# 4  
Old 10-08-2013
Two syntax errors. Within { } the syntax is different
Code:
awk -F',' 'BEGIN {n=0}
{
if (NR == FNR) {fname[$1]; next}
if ($3==fname) n=1
}
END {if (n==0) print}
'

Parts of the main (or the whole main block) can be without { } then the syntax for an implicit if is
Code:
awk -F',' 'BEGIN {n=0}
NR == FNR {fname[$1]; next}
{
if ($3==fname) n=1
}
END {if (n==0) print}
'

Since some time I add brackets to the implicit if, to emphasize the similarity with an explicit if:
Code:
(NR == FNR) {fname[$1]; next}

The implicit if can have an implicit action that is {print}. The explicit if must have an explicit action.

Last edited by MadeInGermany; 10-08-2013 at 07:43 PM..
This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 10-08-2013
Quote:
Originally Posted by MadeInGermany
Two syntax errors. Within { } the syntax is different
Code:
awk -F',' 'BEGIN {n=0}
{
if (NR == FNR) {fname[$1]; next}
if ($3==fname) n=1
}
END {if (n==0) print}
'

Parts of the main (or the whole main block) can be without { } then the syntax for an implicit if is
Code:
awk -F',' 'BEGIN {n=0}
NR == FNR {fname[$1]; next}
{
if ($3==fname) n=1
}
END {if (n==0) print}
'

Since some time I add brackets to the implicit if, to emphasize the similarity with an explicit if:
Code:
(NR == FNR) {fname[$1]; next}

The implicit if can have an implicit action that is {print}. The explicit if must have an explicit action.
Thanks for your such detail explanation, you are great.

More question, what i want to do is:

I have one file called filelist, this is static file. this file is master file for checking source send file status. file like below:
group, filename
abc,file1
abc,file2
abc,file3
cde,file4
cde,file4
def,file5
everyday, I need to check if the all file come or not group by group. which means for group abc, if I found file1, file2, file3,file4 then send group message to downstream (group file completed). if any file missing, I need to send warning. there are about 50 group 150 files. I am DB developer, not that strong in unix. I cannot figure out how to loop file based on group count, so, my idea is:
use awk find the file not existing in dir, then, uniq the group for both file list and the above scritp return, then do some sort of minus using filelist - result return from script, this I can get the file completed group list.
Do you have any suggestion about how to work for this.

Thanks

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

"SQLPLUS -S " is not working in one environment where same code is working in another

"SQLPLUS -S " is not working in one environment where same code is working in another getting below error =================================== SQL*Plus: Release 11.2.0.3.0 Production Copyright (c) 1982, 2011, Oracle. All rights reserved. Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus... (1 Reply)
Discussion started by: yogendra.barode
1 Replies

2. Shell Programming and Scripting

How to make working this regex in perl?

Hello to all, The Regex below is supposed to match all strings except RR45. I've tested in regex101.com and it works, butwhen I try to use it with the perl command below I get the error shown. Regex=(?<=^|RR45)(?!RR45).+?(?=RR45|$) How to fix this? I'm using Cygwin. $ echo... (9 Replies)
Discussion started by: Ophiuchus
9 Replies

3. Shell Programming and Scripting

make file script not working

Hi All, I have one requirement in my automation . I need to pass values like 1 , 2 , 3 to MY_IMAGE in command line in linux . I had defines activities for all these inputs in other make file. The code similar to below i wrote for my requirement. Issue was whenever i passes values... (1 Reply)
Discussion started by: saku
1 Replies

4. AIX

Can I make application for AIX while working on Linux Box

Hi all, I had a large application created using Visual C++. I ported that application using WINE to the Linux platform (ofcourse x86). Now I have to port the same application to AIX which runs over IBM mainframe. I dont have mainframe available but it is required for me to port my application to... (1 Reply)
Discussion started by: noble_curious
1 Replies

5. Shell Programming and Scripting

Please make this code elegant.

Hi All, Following is the part of my script.It does contain many for loops and is not elegant. Please feel free to suggest any changes to make this elegant. Thanks! nua7 for i in `ls $CATALINA_HOME/shared/lib/*.jar`; do LOCALCLASSPATH="$LOCALCLASSPATH:$i" done for i in... (3 Replies)
Discussion started by: nua7
3 Replies

6. UNIX for Dummies Questions & Answers

What can make Cronjobs stop working??

Up until two days ago they were working junt fine, then stoped working with out me doing anything. Yesterday they started working again...and then stoped working, at about the same time of day that they stoped working the day before. service crond restart did nothing. All SSH signs point to... (0 Replies)
Discussion started by: Nintendo
0 Replies

7. HP-UX

make -version is not working in HP-UX

hello everyone, I had a HP-UX, i am trying to find the make version ,but it is displaying the error i.e make -v Make: Unknown flag argument v. Stop. make -version Make: Unknown flag argument v. Stop. make --version Make: Unknown flag argument -. Stop. make -V Make: Unknown flag... (2 Replies)
Discussion started by: mannam srinivas
2 Replies

8. Linux

Need direction to make code for cellphone in C,C++ or Perl

Hi All, I need a help from the techie guys in this group.Actually, i need to make a code which can make wallpaper and ringtone for a mobile phone using any method. I know C,C++ and perl langauges but doesnot having much knowledge of JAVA. So can anybody tell me that whether i can... (0 Replies)
Discussion started by: basileis
0 Replies

9. Programming

How to make a C code reentrant?

Dear reader, This is a query related to multiuser environment. I have a piece of code written in C. Now I want to make this code as reentrant and execute on several trminals at the same time, such that there exists only one copy of code in the memory. Please tell me.. 1. What are the... (2 Replies)
Discussion started by: neelam
2 Replies
Login or Register to Ask a Question