Search with awk problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search with awk problem
# 1  
Old 02-10-2011
Search with awk problem

Hi

There is one problem which i am not able to find the solution Smilie

Suppose there are two files tmpfile1 and tmpfile2 .
tmpfile1 contains data as
Code:
:bash> cat tempfile1
1222
1234
1234
1234
:bash>


now my code is written as
Code:
getcommand="cat tmpfile2"
while(getcommand | getline)
{
 
#Do something
}

Now My question is i want to search in tempfile1 in
Code:
getcommand="cat tmpfile2"
while(getcommand | getline)
{
#### how to search parameter (1222) in tempfile1
#Do something
}


Please help me regarding this.

Last edited by Franklin52; 02-10-2011 at 04:14 AM.. Reason: Please use code tags
# 2  
Old 02-10-2011
Please use code tag while posting any code or your input/output file.
Hi,Try this,
Code:
awk 'NR==FNR{a[$1]++;next}a[$1]' tempfile1 tempfile2

# 3  
Old 02-10-2011
Hi Thanks for your reply

but your solution seems to modify the entire query i can not change the
"getling" query.

neither i can remove the while function as this is exsisting functionality that's y


I think there must be other approach so that we can solve the query.

Please help
# 4  
Old 02-10-2011
Please give what is in tmpfile1 and tmpfile1 and how should the output look like.
# 5  
Old 02-10-2011
Hi all
Thanks for ur reply
Now my detailed problem is
suppose tmpFile1 contains data as
Code:
1222
1223
1224
1225


and tmpfile2 contains the data as
Code:
abc;def 
1601;0000
1222;0001
1603;0002
1112;0003
1224;0004


now initally the code is doing as

Code:
getcommand="cat tmpfile2" 
while(getcommand | getline) 
{
### i want to print only those colums which are not included in tmpFile1 and included in tmpFile2
}



so the expected output will be
Code:
abc;def
1601;0000
1603;0002
1112;0003


I have to do it from above functionality only .
Please help me regarding this.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 02-10-2011 at 11:59 AM.. Reason: please use code tags!
# 6  
Old 02-10-2011
Code:
fgrep -v tmpFile1 tmpFile2

?
# 7  
Old 02-10-2011
Code:
awk  'NR==FNR{a[$1]=$1;next}!a[$1]' temp1 FS=";" temp2


Last edited by yinyuemi; 02-10-2011 at 04:24 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies

3. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

4. Shell Programming and Scripting

Problem passing a search pattern to AWK inside a script loop

Learning, stumbling! My progress in shell scripting is slow. Now I have this doubt: I have the following file (users.txt): AU0909,on AU0309,off AU0209,on AU0109,off And this file (userson.txt) AU0909 AU0209 AU0109 AU0309 I just want to set those users on userson.txt to "off" in... (14 Replies)
Discussion started by: quinestor
14 Replies

5. Programming

Binary Search Tree Search problem

I am writing code for a binary search tree search and when I compile it i am getting strange errors such as, " /tmp/ccJ4X8Xu.o: In function `btree::btree()': project1.cpp:(.text+0x0): multiple definition of `btree::btree()' " What does that mean exactly? tree.h #ifndef TREE_H #define... (1 Reply)
Discussion started by: meredith1990
1 Replies

6. UNIX for Dummies Questions & Answers

Search problem

Hi I have the following problem : i am willing to search over the forum, the posts in which someone proposed a solution that use the command " pr " Of course i tried to launch it on this search key (as well as on "| pr" but the searching doesn't find anything (search string too short ,... (4 Replies)
Discussion started by: ctsgnb
4 Replies

7. Shell Programming and Scripting

Simple awk search problem

Hello; we have : awk '/reg_exp/,0/ prints every line after the first occurrence of "reg_exp" But if I want to print rest of the lines AFTER the last occurrence of "reg_exp", how would I do it ?? Tried : awk ' ! (/reg_exp/,0)' But it errored... Thank you for any... (5 Replies)
Discussion started by: delphys
5 Replies

8. UNIX for Dummies Questions & Answers

ldap search problem

I am posting in this section because in this regard I am a Dummy. I know very little about ldap. We have a couple of ldap registries running on an AIX box. I can connect into those registries using an openldap browser. But I am trying to run some queries against the registry on the server itself,... (1 Reply)
Discussion started by: fwellers
1 Replies

9. Shell Programming and Scripting

Problem with search pattern

Can anyone help me in a scriptfor below example which has to find the string "System && Passcode 0" or "System && Failcode ??" If this searched string occurs consecutively 4 times it should provide output as error S.No : Program: Status 1. was : Passcode 1 2. System: Passcode 0... (1 Reply)
Discussion started by: gantagoru
1 Replies

10. Programming

problem with ldap search using c

hi all i m writin a c program to search ldap db for values. i used the following code after search result return a value >0 if (result==1) { entry=ldap_first_entry(ld,msg); for(....;....;...) { // code to store the data values } } i m gettin an error at... (1 Reply)
Discussion started by: mridula
1 Replies
Login or Register to Ask a Question