Sponsored Content
Full Discussion: Garbage value
Top Forums Shell Programming and Scripting Garbage value Post 302560461 by Corona688 on Friday 30th of September 2011 12:16:55 AM
Old 09-30-2011
I'd test it character by character instead of testing long strings. I'm not too fluent in perl, but hopefully the logic on this should be followable:

Code:
$ cat palindrome.awk
BEGIN { FS=""; ORS=""; }

{
	for(N=1; N<=NF; N++)
	for(M=N+1; M<=NF; M++)
	{
	# If it does not begin and end on the same char, not a palindrome
		if($M != $N) continue;

		A=N ; B=M; P=1;

		# Test towards the middle until A and B cross
		while(P && (B > A))
			if($(B--) != $(A++) ) P=0;

		if(!P) continue;	# Not a palindrome

		printf("Palindrome, %d-%d: ", N, M);
		for(A=N; A<=M; A++) print $A;
		printf("\n");
	}
}
$ echo "AGCTAGCTCGAAGGTAG" | awk -f palindrome.awk
Palindrome, 5-11: AGCTCGA
Palindrome, 6-10: GCTCG
Palindrome, 7-9: CTC
Palindrome, 10-13: GAAG
Palindrome, 11-12: AA
Palindrome, 13-14: GG
$


Last edited by Corona688; 09-30-2011 at 01:22 AM..
This User Gave Thanks to Corona688 For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Garbage characters in display

:confused: I recently left managment and came back to AIX administration. So I am a bit rusty to say the least. The issue I am having is with the term settings when I either simply telnet to my AIX unit or even when I use an emulator like puTTY or a VAR provided one. Once I am logged into... (0 Replies)
Discussion started by: Haleja001
0 Replies

2. Shell Programming and Scripting

Script to Remove Garbage Character

Hello, Whenever I transfer files between machines, I find a garbage character (^M) being appended to the end of every line of the file. Can you suggest a script wherein I can eliminate the garbage character. I tried sed 's/^M//g' < filename > filename1 ...but it doesn't work. Also, this... (4 Replies)
Discussion started by: Eddie_The_Head
4 Replies

3. Shell Programming and Scripting

Removing Garbage output

I am using following code to read myfile.ddl line by line. But the thing is it is printing lot of garbage which are the names of the files and directories in which myfile.ddl is present. Kindly refine the code so that only myfile.ddl contents are only read LOGFILE="logfile.txt"... (4 Replies)
Discussion started by: skyineyes
4 Replies

4. Shell Programming and Scripting

Remove Garbage Output

Hello Friends, In a script i m using different temporary file and i remove them in the end. During script execution i have some garbage output which is not required. For example: Garbage Output ++ rm temp_out temp_a temp_b temp_c ++ rm Filter1 Filter2 Script : Even i am redirecting rm... (7 Replies)
Discussion started by: Danish Shakil
7 Replies

5. Filesystems, Disks and Memory

garbage collection not reflected in the nmon

i have my application running on AIX box (configuration given below) My application does garbage collection pretty well, as such the memory free shows 500 MB - 700 MB freed up in the log statements printed in the application, but the nmon shows the physical space going upwards and does not reflect... (1 Reply)
Discussion started by: mahesh_sivan
1 Replies

6. Programming

strcat outputs garbage

Anyone have any ideas why when using strcat function I would get some garbage at the beginning of the output string? what I'm doing is something like the following example. Code: char temp; char tempHolder; for(int i=0;i<something;i++){ sprintf(temp,"%u ", someVariable);... (2 Replies)
Discussion started by: airon23bball
2 Replies

7. UNIX for Dummies Questions & Answers

Terminal telnet echos garbage

i am trying to make powerterm not echo back this charactor. ≥ When I press control-C I get it that telnet charactor/garbage echos back. how to turn off? where? what config? is there something in powerterm to switch on/off? I do not see it. Redhats offical statement is: "I... (10 Replies)
Discussion started by: olyanderson
10 Replies

8. Programming

Boehm garbage collector for C

is anybody out there experienced with the boehm gc? this is a very simple function: int fn1(){ int *p = (int *) GC_MALLOC(sizeof(int *)); return 0; }after leaving fn1() gc should free p. *** now another example: int* fn2(){ int* p= (int *) GC_MALLOC(sizeof(int... (1 Reply)
Discussion started by: dodona
1 Replies

9. UNIX for Beginners Questions & Answers

Some % of Garbage Collection

I need to write a python script that will look at the local gc logs. 6 sys=0.00, real=0.06 secs] 2019-06-05T07:43:12.029-0500: 1072696.494: 2791209K->1995953K(2796544K)] 2803355K->1995953K(4164608K), , 3.0299555 secs] 2019-06-05T07:43:17.149-0500: 1072701.614: 3334321K->2008193K(4167680K),... (1 Reply)
Discussion started by: xgringo
1 Replies
Regexp::Common::lingua(3)				User Contributed Perl Documentation				 Regexp::Common::lingua(3)

NAME
Regexp::Common::lingua -- provide regexes for language related stuff. SYNOPSIS
use Regexp::Common qw /lingua/; while (<>) { /^$RE{lingua}{palindrome}$/ and print "is a palindrome "; } DESCRIPTION
Please consult the manual of Regexp::Common for a general description of the works of this interface. Do not use this module directly, but load it via Regexp::Common. $RE{lingua}{palindrome} Returns a pattern that recognizes a palindrome, a string that is the same if you reverse it. By default, it only matches strings consisting of letters, but this can be changed using the "{-chars}" option. This option takes a character class (default is "[A-Za-z]") as argument. If "{-keep}" is used, only $1 will be set, and set to the entire match. This pattern requires at least perl 5.6.0. SEE ALSO
Regexp::Common for a general description of how to use this interface. AUTHOR
Damian Conway (damian@conway.org) MAINTAINANCE
This package is maintained by Abigail (regexp-common@abigail.be). BUGS AND IRRITATIONS
Many regexes are missing. Send them in to regexp-common@abigail.be. LICENSE and COPYRIGHT This software is Copyright (c) 2001 - 2009, Damian Conway and Abigail. This module is free software, and maybe used under any of the following licenses: 1) The Perl Artistic License. See the file COPYRIGHT.AL. 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2. 3) The BSD Licence. See the file COPYRIGHT.BSD. 4) The MIT Licence. See the file COPYRIGHT.MIT. perl v5.16.2 2010-02-23 Regexp::Common::lingua(3)
All times are GMT -4. The time now is 10:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy