LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-21-2008, 08:26 AM   #1
thomasknowles
LQ Newbie
 
Registered: Jul 2008
Location: England
Distribution: Ubuntu / OpenBSD
Posts: 3

Rep: Reputation: 0
Simple Scripting Problem [Comparison of several strings] [SOLVED]


Greetings everyone,

First of all I am a first time poster, so "hello", second of all I have a problem, I have been scratching my head and "Googling" for quite some time but still can't find an adequate or reasonably simple solution for my problem.

I have a file and it is delimited by tabs as seen below tabs:

## Short segmentation

Code:
AddTimers	icq.c	root/modules/icq	->	KeepAlive	icq.c	root/modules/icq
AddTimers	icq.c	root/modules/icq	->	SelectServer	icq.c	root/modules/icq
AddTimers	icq.c	root/modules/icq	->	eb_timeout_add	plugin_api.c	root/src
Connect_Remote	send.c	root/modules/icq/libicq	->	ICQ_Debug	libicq.c	root/modules/icq/libicq
Connect_Remote	send.c	root/modules/icq/libicq	->	proxy_connect	libproxy.h	root/libproxy
Connect_Remote	send.c	root/modules/icq/libicq	->	proxy_gethostbyname	libproxy.h	root/libproxy
Connect_Remote	send.c	root/modules/icq/libicq	->	set_nonblock	tcp.c	root/modules/icq/libicq
Connect_Remote	send.c	root/modules/icq/libicq	->	strdup	yahoo_util.h	root/modules/yahoo2/libyahoo2
ayttm-0.2.2	Connect_Remote	send.h	root/modules/icq/libicq	->	ICQ_Debug	libicq.c	root/modules/icq/libicq
If you're asking yourself what the devil that is, it's just a break down of an early version of ayttm, but I digress, this is what I want to do. I wish to match the three strings e.g. (AddTimers icq.c root/modules/icq) on the left hand side of the -> against the three strings on the right hand side of the -> and if they match, remove the entire line.

There are numerous ways I have attempted this, however, due to my lack of competence in bash scripting and regular expressions (I am working on it) both of which have contributed towards my demise. I am not asking for an answer, I will never learn that way, but just a simple push in the right direction.

Thank you for reading.

Thomas Knowles.

edit.

Code:
grep -Ev '^(.+)\s*->\s*\1$' file
submitted by radoulov

Example use

Code:
AddTimers	icq.c	root/modules/icq	->	KeepAlive	icq.c	root/modules/icq
AddTimers	icq.c	root/modules/icq	->	SelectServer	icq.c	root/modules/icq
AddTimers	icq.c	root/modules/icq	->	eb_timeout_add	plugin_api.c	root/src
Connect_Remote	send.c	root/modules/icq/libicq	->	ICQ_Debug	libicq.c	root/modules/icq/libicq
Connect_Remote	send.c	root/modules/icq/libicq	->	proxy_connect	libproxy.h	root/libproxy
yyparse	plural.c	root/intl	->	new_exp_1	plural.c	root/intl
yyparse	plural.c	root/intl	->	new_exp_2	plural.c	root/intl
yyparse	plural.c	root/intl	->	new_exp_3	plural.c	root/intl
yyparse	plural.c	root/intl	->	yyparse	plural.c	root/intl
AddTimers	icq.c	root/modules/icq	->	AddTimers	icq.c	root/modules/icq
Returned values when applying the grep.

Code:
AddTimers	icq.c	root/modules/icq	->	KeepAlive	icq.c	root/modules/icq
AddTimers	icq.c	root/modules/icq	->	SelectServer	icq.c	root/modules/icq
AddTimers	icq.c	root/modules/icq	->	eb_timeout_add	plugin_api.c	root/src
Connect_Remote	send.c	root/modules/icq/libicq	->	ICQ_Debug	libicq.c	root/modules/icq/libicq
Connect_Remote	send.c	root/modules/icq/libicq	->	proxy_connect	libproxy.h	root/libproxy
yyparse	plural.c	root/intl	->	new_exp_1	plural.c	root/intl
yyparse	plural.c	root/intl	->	new_exp_2	plural.c	root/intl
yyparse	plural.c	root/intl	->	new_exp_3	plural.c	root/intl

Last edited by thomasknowles; 07-22-2008 at 03:21 AM. Reason: Alteration of title, inclusion of [code] tags and [SOLVED].
 
Old 07-21-2008, 11:17 AM   #2
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
Code:
grep -Ev '^(.+)  *->  *\1$' file
 
Old 07-21-2008, 11:51 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Your example does not include any lines that meet your criteria...

Watch out for spaces and tabs. eg radulov's code might not work based on whatever non-printing characters follow the "->" (or are embedded in the string to be matched).
 
Old 07-21-2008, 12:34 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
awk '/AddTimers/ && $1==$5 && $2==$6 && $3==$7' file
 
Old 07-21-2008, 03:08 PM   #5
thomasknowles
LQ Newbie
 
Registered: Jul 2008
Location: England
Distribution: Ubuntu / OpenBSD
Posts: 3

Original Poster
Rep: Reputation: 0
Thank You for your replies.
 
Old 07-21-2008, 03:44 PM   #6
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
Quote:
Originally Posted by pixellany View Post
Your example does not include any lines that meet your criteria...

Watch out for spaces and tabs. eg radulov's code might not work based on whatever non-printing characters follow the "->" (or are embedded in the string to be matched).
Yep,
perhaps something like this will be more appropriate:

Code:
grep -Ev '^(.+)\s*->\s*\1$' file
 
Old 07-22-2008, 03:17 AM   #7
thomasknowles
LQ Newbie
 
Registered: Jul 2008
Location: England
Distribution: Ubuntu / OpenBSD
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by radoulov View Post
Yep,
perhaps something like this will be more appropriate:

Code:
grep -Ev '^(.+)\s*->\s*\1$' file
Thank You,

this solution worked absolutely perfectly, I apologise about my ambiguity of my problem description but I see you thwarted that nicely. You have just made my day ten times better.

Thomas Knowles.
 
Old 07-22-2008, 06:53 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Any time that we can "thwart ambiguity", that is a GOOD THING.....
 
  


Reply

Tags
bash, compare, expressions, grep, line, read, regular, remove



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
Simple Scripting Help hopspitfire Linux - General 2 06-12-2007 04:46 PM
simple scripting help please kb100 Programming 7 08-23-2006 06:31 AM
simple scripting help please kb100 Programming 12 08-18-2006 08:34 AM
simple scripting help please kb100 Programming 3 08-18-2006 08:08 AM
simple shell scripting problem noir911 Programming 11 03-14-2006 01:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:53 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
Open Source Consulting | Domain Registration