fun and easy awk question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers fun and easy awk question
# 1  
Old 01-25-2011
fun and easy awk question

I have a file called mytitles.txt containing a list of book titles
I have a second file called abfile.txt containing a list of book titles (in the 3rd field) and it has author info and copyright year info as well..

I want to search mytitles.txt for a match in the 3rd field of abfiles.txt, and if there is a match found, I want to print that whole line from abfiles.txt to foundfiles.txt...

I would use a for loop like %for i in mytitles.txt do awk ;{if ($i ==$3) print}' or something like that, but as you can see, I don't know how to do this type of for loop in awk.

---------- Post updated at 11:54 AM ---------- Previous update was at 11:20 AM ----------

I should specify the field separator in abfiles.txt is double quotes (") but in mytitles.txt it is simply titles, some with spaces, some a single word.
# 2  
Old 01-25-2011
Can you give example lines from each file?
# 3  
Old 01-26-2011
My File with Titles:
Code:
Close Range
VANISHED MAN 
Cold Moon 
1776
Creating Wealth 
Dante Club

File I want to find matches in with field separator being " so the title would be $2.. If found a match, I want to print the whole line from this file:
Code:
  d5of5 Vanished Man    9780743551717    "VANISHED MAN"    "DEAVER, JEFFERY"    2005
 CD01of10 1776UAB    9780743551779    "1776"    "MCCULLOUGH, DAVID"    2005

----------
the lines above should be printed to a newfile, because they matched with the first file.


I hope I am being clear, thanks for your help.

---------- Post updated 01-26-11 at 09:24 AM ---------- Previous update was 01-25-11 at 01:31 PM ----------

Please remove this thread

Last edited by glev2005; 01-25-2011 at 02:48 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk diamond code golf (just for fun!)

Hey guys, This is purely just a little bit of fun with awk. I realize this this isn't that constructive so please remove if need be. Your goal: Create a one line awk script that generates a diamond shape of any size. Both the size of the diamond (measured by its middle line) and the... (7 Replies)
Discussion started by: pilnet101
7 Replies

2. Shell Programming and Scripting

awk easy question

So, I have the following code: cat testfile.txt | awk -F, '{ print $1" "$2" "$3" "$4" "$5 }' | read DOC ORG NAME echo "$DOC" echo "$ORG" echo "$NAME" My testfile.txt looks something like the following: Document Type,Project Number,Org ID,Invoice Number It will eventually be more... (14 Replies)
Discussion started by: Parrakarry
14 Replies

3. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies

4. Shell Programming and Scripting

More fun with awk

#!/usr/bin/ksh ls -l $@ | awk ' /^-/ { l = 5*log($5) h = sprintf("%7d %-72s",$5,$8) print "\x1B ls command with histogram of file sizes. The histogram scale is logaritmic, to avoid very short bars for smaller files or very long bars for bigger files. Screenshot: (4 Replies)
Discussion started by: colemar
4 Replies

5. Shell Programming and Scripting

Fun with awk

uggc://ra.jvxvcrqvn.bet/jvxv/EBG13 #!/usr/bin/awk -f BEGIN { for (n=0;n<26;n++) { x=sprintf("%c",n+65); y=sprintf("%c",(n+13)%26+65) r=y; r=tolower(y) } } { b = "" for (n=1; x=substr($0,n,1); n++) b = b ((y=r)?y:x) print b } ... (0 Replies)
Discussion started by: colemar
0 Replies

6. UNIX for Dummies Questions & Answers

easy question

Hi everybody: Could anybody tell me if I have several files which each one it has this pattern name: name1.dat name2.dat name3.dat name4.dat name10.dat name11.dat name30.dat If I would like create one like: name_total.dat If I do: paste name*.dat > name_total.dat (15 Replies)
Discussion started by: tonet
15 Replies

7. Shell Programming and Scripting

Easy AWK question

Ive got some output in a file that looks exactly like this: 1 ----------- 1542 1 record(s) selected. How do I just extract that 1542 and drop it into another file or (preferrably) a variable (using a ksh script) (9 Replies)
Discussion started by: rdudejr
9 Replies

8. UNIX for Dummies Questions & Answers

Easy question about awk gsub

How does one escape the left bracket in awk? For example: | awk 'gsub (" I'm sure it's pretty simple, I'm just a noob. (1 Reply)
Discussion started by: TheCrunge
1 Replies

9. Shell Programming and Scripting

A easy question.

this is the simple question, please help me! the question is: how to send exactly 50 ICMP Echo request packets with 500 bytes of payload to 202.139.129.221? I tried to use ping -F 500 202.139.129.221, but it didn't work. Thanks! (6 Replies)
Discussion started by: kikikaka
6 Replies
Login or Register to Ask a Question