UNIX commands in AWK


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers UNIX commands in AWK
# 1  
Old 01-19-2011
UNIX commands in AWK

Hi, I have 2 lists of words and I need to take every line in first_list.txt and use agrep command to find similar words in whole second_list.txt.

I tried to use AWK, but I dont know how to take current line ($0) and use in inside of agrep

Code:
cat first_list.txt | awk ''

Thanks for help
# 2  
Old 01-19-2011
Please give more clue : thanks to provide a representative sample of input and expected output
# 3  
Old 01-19-2011
Try a loop:

while read pattern
do
agrep $pattern secondlist.txt
done < firstlist.txt

or

agrep -f firstlist.txt secondlist.txt

The -f option tells agrep to read patterns from the first file. However, it works only for exact match and for simple patterns.
# 4  
Old 01-19-2011
Code:
fgrep first_list.txt second_list.txt

grep -f first_list.txt second_list.txt

# 5  
Old 01-19-2011
I would like to use more than one command, or something else (like grep). So I would use first one, the loop.But Idk why it doesnt work.

A agrep was just an example.

---------- Post updated at 12:16 PM ---------- Previous update was at 12:13 PM ----------

Okay, here is another example..

1)Read first line in first_list.txt
- search this line in second_list.txt using grep
- print the result
2) Read second line..
...
3) Read third line ...
...

and so on
# 6  
Old 01-19-2011
Is this homework?
# 7  
Old 01-19-2011
Quote:
Originally Posted by fpmurphy
Is this homework?
No its not, its just for my personal use :-).
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK commands, in different OS

I have developed a bash shell script which works perfectly fine when any bash shell is in use except SunOS. There are two commands that is not compatible. #!/usr/bin/env bash Problem 1. The awk command below does not work for SunOS Requirement We extract Oracle EBS tables into text... (9 Replies)
Discussion started by: uuuunnnn
9 Replies

2. Shell Programming and Scripting

Help me in awk commands

can you please let me know what does the below awk command does. awk 'NR>2{printf "%-30s %-15s\n", $1, !($4)?$2:$4;}' result.txt (1 Reply)
Discussion started by: ramkumar15
1 Replies

3. Fedora

Help with Unix commands

Hi, I have the following file called addresses, (it is a large file i have only copy and pasted few of the data below) and I am wanting to write a command so it will Find the ratio of mobile (07....) to land line (01....) telephone numbers? then find the most popular first name and list the... (2 Replies)
Discussion started by: tina_2010
2 Replies

4. UNIX for Dummies Questions & Answers

Help with Unix Commands

Hello everybody, I am a newbie in Unix/Linux so please excuse me!:o Could somebody please explain to me what the following Unix commands do or mean: ls -al | grep "*.c" | wc -l >> log.txt and ps -el | grep "*tty*" | uniq | sort > log.txt I know 'grep' means to find a text... (4 Replies)
Discussion started by: kev_1234
4 Replies

5. UNIX for Dummies Questions & Answers

Running UNIX commands remotely in Windows box from Unix box – avoid entering password

I am able to run the UNIX commands in a Windows box from a UNIX box through "SSH" functionality. But whenever the SSH connection is established between UNIX and Windows, password for windows box is being asked. Is there a way to avoid asking password whenever the SSH connection is made? Can I... (1 Reply)
Discussion started by: D.kalpana
1 Replies

6. UNIX for Dummies Questions & Answers

Help with these unix commands!

Hi to all, I have just started to learn Unix, and am having problems trying to understand the following two unix commands. if any1 could help i would greatly appreciate it. 1) ls -s | sort -nr | head -3 2) man -k c | grep -i ' c* ' | grep 1 i understand that for 1) the command will... (7 Replies)
Discussion started by: Vn3050
7 Replies

7. Shell Programming and Scripting

How to use unix commands in awk

Hi All, I try to use the unix commands inside awk and couldnt succeed . Please help me how to achieve it. Regards, Sukumar. (7 Replies)
Discussion started by: jerome Sukumar
7 Replies

8. Shell Programming and Scripting

combining unix commands and awk program

Dear Experts I am trying to find if it is possible to combine unix commands in awk program. For example if it is possible embed rm or ls or any unix command inside the awk program and while it is reading the file besides printing be able to do some unix commands. I am thinking may be just print... (2 Replies)
Discussion started by: Reza Nazarian
2 Replies

9. Windows & DOS: Issues & Discussions

Unix commands

I am trying to find the difference between the sum and join commands in Unix. If there is one, what is it? and what they do :cool: (1 Reply)
Discussion started by: Darwin Rodrigue
1 Replies

10. UNIX for Dummies Questions & Answers

Maingrame to UNIX sending UNIX commands

I want to know if there is a way to send unix commands thru FTP from a mainframe to kick off Autosys Jobs. I just need to send a command from the mainframe to UNIX and have UNIX execute that command. (2 Replies)
Discussion started by: skammer
2 Replies
Login or Register to Ask a Question