I want to compare tmp file file name with list file 2nd column, if file name in both file, then print entire record from list, if file name only exists in list then print "not found" plus the record. for above two file, I except get below result:
Code:
cde,file4
cde,file5
def,file6
Not Found def,file7
Not Found def,file8
abc,file1
abc,file2
abc,file3
Not Found acd,file9
Not Found acd,file10
Not Found cde,file4
Not Found cde,file5
Not Found def,file6
Not Found def,file7
Not Found def,file8
Not Found abc,file1
Not Found abc,file2
Not Found abc,file3
Not Found acd,file9
Not Found acd,file10
Hope the experts in the forum take a look, tell me where I did wrong and how to fix this.
awk -F"," 'NR==FNR{a[$1];next}{if ($2 in a) print a[$1],$0;else print "Not Found", $0;}' tmplist srclist
Code:
awk: syntax error near line 1
awk: illegal statement near line 1
awk: illegal statement near line 1
My server is SunOS 5.10 Generic_144488-17 sun4v sparc SUNW,SPARC-Enterprise-
would you please take a look.
Thanks in advance
---------- Post updated at 11:56 AM ---------- Previous update was at 11:52 AM ----------
Quote:
Originally Posted by Akshay Hegde
Correct your code like this
Code:
awk -F, 'FNR==NR{_[$1];next}{print ($2 in _)?$0:"Not Found" OFS $0}' tmp list
Code:
cde,file4
cde,file5
def,file6
Not Found def,file7
Not Found def,file8
abc,file1
abc,file2
abc,file3
Not Found acd,file9
Not Found acd,file10
Thanks for your replay.
when using the code you provide, I got error.
awk: syntax error near line 1
awk: illegal statement near line 1
My server is SunOS 5.10 Generic_144488-17 sun4v sparc SUNW,SPARC-Enterprise-
by the way, would you please briefly explain what "_[$1]", "($2 in _)?" mean?
I need to compare to find filename existing in srclist but not in tmplist.
I use code as below:
Code:
nawk -F"," 'NR==FNR{a[$4]=$0;next}{if ($2 in a) print $0,"," "Found";else print $0,"," "Not Found";}' tmplist srclist
and I got below result:
Code:
cde,file4 ,Found
cde,file5 ,Not Found
def,file6 ,Not Found
def,file7 ,Not Found
def,file8 ,Not Found
abc,file1 ,Found
abc,file2 ,Found
abc,file3 ,Found
acd,file9 ,Not Found
acd,file10 ,Not Found
I have one issue, I need print out the first 3 columns from tmplist, I tried below code, but it doesn't work.
Code:
nawk -F"," 'NR==FNR{a[$4]=$0;next}{if ($2 in a) print $0,a[$1],"," "Found";else print $0,"," "Not Found";}' tmplist srclist
for my understanding, a[$1] should be first file first column, but it isn't.
how can I print first file's column in my code?
I need to compare to find filename existing in srclist but not in tmplist.
I use code as below:
Code:
nawk -F"," 'NR==FNR{a[$4]=$0;next}{if ($2 in a) print $0,"," "Found";else print $0,"," "Not Found";}' tmplist srclist
and I got below result:
Code:
cde,file4 ,Found
cde,file5 ,Not Found
def,file6 ,Not Found
def,file7 ,Not Found
def,file8 ,Not Found
abc,file1 ,Found
abc,file2 ,Found
abc,file3 ,Found
acd,file9 ,Not Found
acd,file10 ,Not Found
I have one issue, I need print out the first 3 columns from tmplist, I tried below code, but it doesn't work.
Code:
nawk -F"," 'NR==FNR{a[$4]=$0;next}{if ($2 in a) print $0,a[$1],"," "Found";else print $0,"," "Not Found";}' tmplist srclist
for my understanding, a[$1] should be first file first column, but it isn't.
how can I print first file's column in my code?
Any input is really really appreciate.
Thanks in advance
Whether this is your interest ??
Code:
$ nawk -F"," 'NR==FNR{a[$4]=$3;next}{if ($2 in a) print $0","a[$2] ",""Found";else print $0",""----""," "Not Found";}' tmplist srclist
cde,file4,11:42,Found
cde,file5,----,Not Found
def,file6,----,Not Found
def,file7,----,Not Found
def,file8,----,Not Found
abc,file1,11:42,Found
abc,file2,11:42,Found
abc,file3,11:43,Found
acd,file9,----,Not Found
acd,file10,----,Not Found
Last edited by Akshay Hegde; 10-09-2013 at 02:47 PM..
Reason: color to highlight
This User Gave Thanks to Akshay Hegde For This Post:
Not sure where the problem is. I can run the script without any issue using the following command.
. /opt/app/scripts/cdc_migration.sh
But it fails with the below error when I try it this way
/opt/app/scripts/cdc_migration.sh
/opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
All,
I have a basic buzz program written in python with return function. If i change return with print,it works fine but i want to know whats wrong with return statement.Can anyone help me whats wrong with this
#!/usr/bin/python
def div4and6(s,e):
for i in range(s,e+1):
if... (5 Replies)
hi,
I am trying to get the FileType using the File command. I have one file, which holds Group separator along with ASCII character.
It's a Text file.
But when I ran the File command the FileType is coming as "data".
It should be "ASCII, Text file".
Is the latest version of File... (6 Replies)
Hi,
I need a shell script, which would search the result values from another files.
1)execute " select column1 from table_name" query on the table.
2)Based on the result, need to be grep from .wft files.
could please explain about this.Below is the way i am using.
#!/bin/sh... (4 Replies)
Hi ! all I am just trying to check range in my datafile
pls tell me why its resulting wrong
admin@IEEE:~/Desktop$ cat test.txt
0 28.4
5 28.4
10 28.4
15 28.5
20 28.5
25 28.6
30 28.6
35 28.7
40 28.7
45 28.7
50 28.8
55 28.8
60 28.8
65 28.1... (2 Replies)
Hi,
I have a problem that I am sure someone will know the answer to. Currently I have a script which returns a binary output if it finds a certain search string (in this case relating to a DRBD cluster) as follows:
searchstring="cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate"
&& echo... (3 Replies)
I have a sun4u system running Solaris 8. I tried running the df command but it returns a blank result. Also I'm unable to collect an explorer from this system as the OS complains that the disk is full. What could be going on here? (10 Replies)
What Im basically trying to do is this:
I have a small script that can grep any parameter entered into a search string, then print to the screen the name of each file the parameter appears in as well as the file path, ie the directory.
The code Im using just for this is....
Directory... (3 Replies)
Hi All,
I amlearning UNIX scripting. I have a small query. I would be thankful if any one helps me out.
I have a below piece of code which delets the files. If file dosent have the permissions to delete a particular file I have used 2>>operator to track the error code.
But my objective is... (1 Reply)