LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-13-2009, 05:02 PM   #16
adelaide98
LQ Newbie
 
Registered: May 2009
Posts: 13

Original Poster
Rep: Reputation: 0

ghostdog74, actually your explanations are very nice and incredibly helpful. thanks very much. the links to awk sites are also great- thanks!

here's what i came up with:
Code:
#!/bin/bash

awk '{
        if (($2" "$1) in animals)
                {print $2,$1> "animaltemp"}
        else {animals [$1" "$2]=""}}
END {
        for(i in animals) {print i>"animaltemp2"}
}' animals
This gives me
Code:
> more animaltemp
dog cat
hamster dog
and
Code:
> more animaltemp2
pig hamster
dog cat
wolf pig
hamster dog
columnA columnB
My final wish is to be able to create a file like animaltemp2 but with markings at dog cat and hamster dog so that I know that I removed reciprocals for them.

I tried to adapt an earlier script from coulcix with a grep and a while statement, but it didn't work. Could anyone tell me why and how to accomplish this last task? Here's what I tried:

Code:
#!/bin/bash
while read line
do
        if grep -qf animaltemp animaltemp2
        then
                echo $line recip deleted >> "animaltemp3"
        else
                echo $line >>"animaltemp3"
        fi
done < animaltemp2
the result is:
Code:
>more animaltemp3
pig hamster recip deleted
dog cat recip deleted
wolf pig recip deleted
hamster dog recip deleted
columnA columnB recip deleted
Much thanks again!
 
Old 05-14-2009, 12:57 PM   #17
adelaide98
LQ Newbie
 
Registered: May 2009
Posts: 13

Original Poster
Rep: Reputation: 0
i figured it out! :)

I'm shocked that I figured it out (there was MUCH trial and error)...

Code:
grep -f animaltemp animaltemp2 | awk '{print $0, "recip" > "animaltemp3"}'
grep -vf animaltemp animaltemp2 >> animaltemp3
Thanks again to everyone who read this and helped.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Increasing the number of concurrent imap connections allowed from any one IP address rsleventhal Red Hat 12 07-18-2008 11:36 AM
Is the number of PC with Linux installed now increasing exponentially ? frenchn00b General 7 04-08-2008 11:27 PM
increasing the number of file descriptors on RHEL8 mingram27 Fedora 1 02-21-2007 01:41 PM
Shell-script question about getting a number as a variable stormrider_may Programming 9 03-14-2006 09:18 AM
Increasing Number of message queues systemwide raees Linux - General 1 01-09-2004 03:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration