How to match the below conditions?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to match the below conditions?
# 8  
Old 01-14-2015
Getting below errors:
Code:
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 5
awk: bailing out near line 5


file1.txt

file2.txt
# 9  
Old 01-14-2015
Quoting Don Cragun:
Quote:
If you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk .
This User Gave Thanks to RudiC For This Post:
# 10  
Old 01-14-2015
Thanks AWK worked Smilie

Thanks RudiC.. Seems I need to remember this..Smilie

But I am afraid why it returns nothing while I know atleast a case exists as belowSmilie:

File1 contains below Column # 12 & Column # 28

Code:
{{ bsmID { amecID 10, moiRdn 1}, moiRdn 3}};RSL 12

& File2 does not contain Column # 19 & Column # 29 as expected

Code:
{{ bsmID { amecID 10, moiRdn 1}, moiRdn 3}};tre 12

---------- Post updated at 05:50 PM ---------- Previous update was at 05:46 PM ----------

Sample files are in my previous post
Code:
https://www.unix.com/302931599-post8.html

# 11  
Old 01-14-2015
As I said: untested because no sample file available. So the tests are up to you.

And, what do you mean with "...File2 does not contain Column # 19..."? Does it or doesn't it?
And, your request was for "TRE" in col 29, above you post "tre".

To me, it'd be normal and logical that no match is found.

Last edited by RudiC; 01-14-2015 at 08:35 AM..
# 12  
Old 01-15-2015
Now I run this (Note: I changed TRE to tre)..

Code:
/usr/xpg4/bin/awk     'NR==FNR        {sub (/RSL /, "", $28)
                         T[$12]=$28
                         next
                        }
         $19 in T       {sub (/tre /, "", $29)
                         if ($29 == T[$19]) print $19, T[$19]
                        }
        ' FS=";" file1 file2

This time it is not blank.. there few lines but not the same as I expected..

Here is one example what should have happened.

File1 contains below Column # 12 & Column # 28


Code:
{{ bsmID { amecID 10, moiRdn 1}, moiRdn 3}};RSL 12

& File2 DOES NOT contain Column # 19 & Column # 29 as expected


Code:
{{ bsmID { amecID 10, moiRdn 1}, moiRdn 3}};tre 12


The script was expected to print
Code:
{{ bsmID { amecID 10, moiRdn 1}, moiRdn 3}};RSL 12

# 13  
Old 01-15-2015
Try
Code:
awk     'NR==FNR        {T[$12]=$28
                         next 
                        }
         $19 in T       {sub (/tre/, "RSL", $29)
                         if ($29 != T[$19]) print $19, T[$19]
                        }   
        ' FS=";" OFS=";" /tmp/file1.txt /tmp/file2.txt

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

awk to print fields that match using conditions and a default value for non-matching in two files

Trying to use awk to match the contents of each line in file1 with $5 in file2. Both files are tab-delimited and there may be a space or special character in the name being matched in file2, for example in file1 the name is BRCA1 but in file2 the name is BRCA 1 or in file1 name is BCR but in file2... (6 Replies)
Discussion started by: cmccabe
6 Replies

4. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

5. Shell Programming and Scripting

awk to match field between two files and use conditions on match

I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Discussion started by: cmccabe
3 Replies

6. Shell Programming and Scripting

Display match or no match and write a text file to a directory

The below bash connects to a site, downloads a file, searches that file based of user input - could be multiple (all that seems to work). What I am not able to figure out is how to display on the screen match found or no match found" and write a file to a directory (C:\Users\cmccabe\Desktop\wget)... (4 Replies)
Discussion started by: cmccabe
4 Replies

7. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

8. Shell Programming and Scripting

Errors in if conditions with to many OR conditions

Hi ALL I have a script where in i need to check for several values in if conditons but when i execute the script it throws error such as "TOO MANY ARGUMENTS" if then msg="BM VAR Issue :: bmaRequestVAR=$bmaRequestVAR , nltBMVAR=$nltBMVAR , bmaResponseVAR=$bmaResponseVAR ,... (10 Replies)
Discussion started by: nikhil jain
10 Replies

9. UNIX for Dummies Questions & Answers

move files that match specific conditions

Hi all, I'm new to this forum and bash scripting. I have the following problem, I need to copy some files (from one dir. to another) whose first 5 numbers (subjects' ID) match the directory names. Here a shortened version of what I'm trying to do: names=(32983_f 35416_f 43579_f) # these are... (6 Replies)
Discussion started by: ada1983
6 Replies

10. UNIX for Dummies Questions & Answers

Lynx Grep Pattern Match 2 conditions Print from Start to End

I am working on a scraping project and I am stuck at this tiny grep pattern match. Sample text : FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. ABC Personal Planning Catherine K. Wat Cath Wat Catherine K. Wat Catherine K. Wat IFRAME:... (8 Replies)
Discussion started by: kkiran
8 Replies
Login or Register to Ask a Question