Search of multiple numeric entries in an output file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Search of multiple numeric entries in an output file
# 1  
Old 04-25-2019
Search of multiple numeric entries in an output file

Hello Tech Guys,

I have two files named check.txt and output.txt

Content of check.txt

Code:
620070527336551	 40201800027285
620070551928314	 40201800027285
620070534376312	 40201800027285
620070536668046	 02711306140261
620070248491123	 02711306140261
620070553851296	 02711306140261
620070446225438	 02711306140261
620070544871702	 02711306140261

Content of output.txt

Code:
# extended LDIF
#
# LDAPv3
# base <data=40201800027285
# filter: (objectclass=*)
# requesting: ALL
#

# 40201800027285
dn: data=40201800027285
data: 40201800027285
objectClass: device2g3g
locked: 000000000000000
locked: 620070527336551
locked: 620070000095731
locked: 620070534376312

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1
# extended LDIF
#
# LDAPv3
# base <data=02711306140261
# filter: (objectclass=*)
# requesting: ALL
#

# 02711306140261
dn: data=02711306140261
data: 02711306140261
objectClass: device2g3g
locked: 620070263383027
locked: 620070551073690
locked: 620070446225438
locked: 620070555544259
locked: 620070453835231
locked: 620070248491123
locked: 620070556469603
locked: 620070536668046

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

The output.txt contains the search of two numeric data numbers i.e. 40201800027285 and 02711306140261 (could be more than two). Against each of these two numeric values the system provided the total number of locked items (could be more). Now I need to compare these locked items alongwith the items present in search.txt in 1st coloum and need to know the difference. The desired output after comparing these two files will be saved in difference.txt and should be like below:

Code:
data: 40201800027285
locked: 620070527336551    620070534376312
unlocked: 620070551928314

data: 02711306140261
locked: 620070536668046    620070248491123    620070446225438
unlocked: 620070553851296    620070544871702

Kindly suggest a code for the above described requirement. Efforts will be really appreciable.

Thanks.

Last edited by vgersh99; 04-25-2019 at 06:36 PM.. Reason: added code tags to the ouput
# 2  
Old 04-25-2019
Any attempts on your side?
# 3  
Old 04-25-2019
Hello. Well no because I am new to shell scripting and doesn't know how to compare and make such logic. Any input would be highly appreciable.
# 4  
Old 04-25-2019
Quote:
Originally Posted by Xtreme
Hello. Well no because I am new to shell scripting and doesn't know how to compare and make such logic. Any input would be highly appreciable.
I know I shouldn't be doing this and should make you work it out yourself, but I'll bend the rules a bit IF you go though the code yourself try to understand it yourself with the minimum of guidance...
awk -f xtreme.awk check.txt output.txt where xtreme.awk is:
Code:
FNR==NR {f1[$1]=$2;next}
/^data:/ { data=$2;next}
data && /^locked:/ && $2 in f1 { locked[$2];next}
data && !NF {
   printf("data: %s\n%s", data, "locked:")
   for(i in locked)
     printf("%s%s", OFS, i)

   printf("%s%s",  ORS, "unlocked:")
   for(i in f1)
     if (!(i in locked) && f1[i]==data)
        printf("%s%s", OFS, i)
   print ORS
   data="";split("", locked)
}

produces:
Code:
data: 40201800027285
locked: 620070534376312 620070527336551
unlocked: 620070551928314

data: 02711306140261
locked: 620070446225438 620070248491123 620070536668046
unlocked: 620070553851296 620070544871702

This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 04-26-2019
This is super !!! I have tried once and it really works. Thank you so much for putting an effort. I will try to understand the logic as much as I can. Loving this forum. Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

2. UNIX for Dummies Questions & Answers

Search file and print everything except multiple search terms

I'm trying to find a way to search a range of similar words in a file. I tried using sed but can't get it right:sed 's/\(ca01\)*//'It only removes "ca01" but leaves the rest of the word. I still want the rest of the information on the lines just not these specific words listed below. Any... (3 Replies)
Discussion started by: seekryts15
3 Replies

3. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

4. Shell Programming and Scripting

Using a single "find" cmd to search for multiple file types and output individual files

Hi All, I am new here but I have a scripting question that I can't seem to figure out with the "find" cmd. What I am trying to do is to only have to run a single find cmd parsing the directories and output the different file types to induvidual files and I have been running into problems.... (3 Replies)
Discussion started by: swaters
3 Replies

5. Shell Programming and Scripting

Storing or Using Numeric Output From a Function

Hi all, I'm trying to implement a linear congruential pseudorandom number generator (<http://en.wikipedia.org/wiki/Linear_congruential_generator>), since $RANDOM and /dev/random aren't standardized. I'm referring to the Shell & Utilities volume of POSIX.1-2008, but I'm running into some odd... (3 Replies)
Discussion started by: PehJota
3 Replies

6. Shell Programming and Scripting

AWK: Discrepancy in numeric output

During a file-system cleanup I noticed a strange behavior of awk (HP-UX 11iv3 / IA64). When summing up the size of files in one directory it gives different numbers when using print as opposed to printf: find . -type f -name '*.dmp.Z' -mtime +35 -exec ls -l {} \+ | \ awk 'BEGIN{ OFMT="%f" } {... (1 Reply)
Discussion started by: pludi
1 Replies

7. Shell Programming and Scripting

Check for Numeric output in Perl

Hi All, I would like to convert my below csh script to Perl. Can any expert help ? # To check for numeric input set tested1 = `echo "$tested"| awk '/^+$/'`; # To remove un-neccessary zeros set tested2 = `echo "$tested"|awk '{print $0+0}'`; (3 Replies)
Discussion started by: Raynon
3 Replies

8. UNIX for Dummies Questions & Answers

SED command to search for numeric and replace

Hi I am very new to linux and scripting. I need to replace numbers abc with number xyz inputting from a reference file. I used the following command - sed "s/$grd/$lab/" , where $grd and $lab comes from reference file. The problem is the above line doesnt take care of space..... (1 Reply)
Discussion started by: ajayh
1 Replies

9. UNIX for Dummies Questions & Answers

rename multiple files from search output

Variations of multiple renames seems to come up a lot but i can't find the answer to this situation. Tidying up a directory where people rename files to .working, .bob, .attempt1 & so on. what i am trying to do is: list the file type, & rename from ".whatever" to .fixed. As the ".whatever" is... (5 Replies)
Discussion started by: woodstock
5 Replies

10. Shell Programming and Scripting

Bourne: search for a non-numeric character in $VAR

if $1 = "123x456", how can I test for the non-numeric character 'x' in that string. I've tried expr with "" but it did not find the x. Any ideas? Can this perhaps be done with sed? Thanks. (2 Replies)
Discussion started by: lumix
2 Replies
Login or Register to Ask a Question