Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


awk "if not exists in (cat filename)"

awk "if not exists in (cat filename)"

awk "if not exists in (cat filename)"

i don't know if i am blaming me with my question, but i have the following "problem".
File one looks like:
gdsfa9078470840 uiupqepquwerop8973070780570

file two is a list with numbers.
334 ...

What i need to do is, to check every line in file one, if on Position 10-12, there is one of the numbers, listed in file 2. Then this line should be ignored.
The rest of the lines schould be wrinten in a new file output.txt

Maybe i am trying it with the wrong tool i don't know...

I would apreciate if someone could give me an advice..


RE: awk "if not exists in (cat filename)"

THANK YOU!!!! Yes it works!

RE: awk "if not exists in (cat filename)"

Great, you have your answer. To keep your mind opened, I give you two other ways:


sed 's/.*/.........&/' pattern.txt|grep -vf - filepattern.txt


sed 's/.*/.\\{9\\}&/' pattern.txt|grep -vf - filepattern.txt

Where filepattern.txt is the first file you described, and pattern.txt, the second.

RE: awk "if not exists in (cat filename)"



sed 's/.*/^.........&/' pattern.txt|grep -vf - filepattern.txt


sed 's/.*/^.\\{9\\}&/' pattern.txt|grep -vf - filepattern.txt

RE: awk "if not exists in (cat filename)"

Hi FlorianAwk.. thanks a lot for your solution too! REGEXs are impressing me everytime :)

@PHV for me to understand it better.. what exactly is the funktion of
I can imagine what, but i could not find an examble which i can say i could understand to 100% and be absolutely sure about the function of it..

I hope you have 5 min to explain it.

RE: awk "if not exists in (cat filename)"

n contains the entries from filetwo=$1..

and the second "n" in  (substr($0,10,3) in n) reffers to fileone

ok i have it..


RE: awk "if not exists in (cat filename)"

is it possible to put this in an IF request?

the whole thing changed a little bit, and i have now to check, if the current line from fileone, whichis in access from awk, if the substring has a value which exists in filetwo, then i have to do something....

so i tried over ...

CODE --> bash

cat fileone | awk 'val=substring($0.10,3); if (grep -q val "filetwo"){printf(val"\n")}' 

so i thougt if the IF request is true, i will get an output. But i get ALL as result. No filtering.
it don't works...

I would apreciate every idea!


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close