LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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-11-2011, 11:13 AM   #16
klambo
LQ Newbie
 
Registered: Jul 2011
Location: Ireland
Distribution: backtrack5
Posts: 5

Rep: Reputation: Disabled

Quote:
Originally Posted by wje_lq View Post
First of all, I hope you realize that to send to a file all 10-character combinations of the following characters
Code:
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
such that no two adjacent characters are of equal value, and placing each combination on its own line, will generate a file that's 31 petabytes long. I hope you have room for this.

The program listed below will generate that file. Just redirect standard output to a file in the normal manner.

No, I haven't tested it to completion. But you can test a crippled version of it by doing these four things:
  1. Comment out the first definition of *character-set*, by adding a semicon at the beginning of the line.
  2. Uncomment the second definition, which just uses "ABC", by removing the semicolon from the beginning of the line.
  3. Comment out the first definition of *word-length*.
  4. Uncomment the second definition, which uses a word length of four.
If you do that and run the program, you'll get this output. That's the kind of output you're looking for, right?
Code:
ABAB
ABAC
ABCA
ABCB
ACAB
ACAC
ACBA
ACBC
BABA
BABC
BACA
BACB
BCAB
BCAC
BCBA
BCBC
CABA
CABC
CACA
CACB
CBAB
CBAC
CBCA
CBCB
So here's the code, all 42 lines of it.
Code:
#!/usr/bin/clisp

(defparameter *character-set* "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
;(defparameter *character-set* "ABC")     ; < --- this line is for testing

(defparameter *word-length* 10)
;(defparameter *word-length* 4)           ; < --- this line is for testing

(defparameter *character-list*
   (coerce *character-set* 'list))

(defun final-char (in-string)
   (cond
      ((> (length in-string) 0)
         (elt in-string (1- (length in-string))))
      (t
         nil)))

(defun new-char-list (in-string)
   (let ((result))
      (mapcar
         (lambda (candidate)
            (cond
               ((not (eql candidate (final-char in-string)))
                  (push candidate result))))
         *character-list*)
      (nreverse result))
      )

(defun extend-string (in-string desired-length)
   (mapcar
      (lambda (new-char)
         (let ((new-string (concatenate 'string in-string (string new-char))))
            (cond
               ((>  (length new-string) desired-length))
               ((>= (length new-string) desired-length)
                  (format t "~a~%" new-string))
               (t
                  (extend-string new-string desired-length)))))
      (new-char-list in-string)))

(extend-string "" *word-length*)
Hope this helps.


Thanks for this Is there a way so save the results to txt file ?

I worked it out clisp clisptxt > file.txt

Last edited by klambo; 07-11-2011 at 11:29 AM.
 
Old 08-08-2011, 08:50 PM   #17
k3eper
LQ Newbie
 
Registered: Aug 2011
Posts: 1

Rep: Reputation: Disabled
Wink Same thought

wje_lq Brilliant script lol! I had this same thought the other day and was trying to fudge crunch and grep together.

Could you maybe suggest changes needed to get rid of any repeating characters in each word at all

EXAMPLE:

Current ABATRWHS
NEW: ATEFUZWH

No character is the same character.

Again awsome script lol so simple really do wish i could script.

Last edited by k3eper; 08-08-2011 at 08:51 PM. Reason: oops
 
Old 08-10-2011, 07:55 PM   #18
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,561

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
Try raising your own question and referencing this one as most people do not follow SOLVED questions (for a fairly obvious reason)
 
Old 08-24-2011, 10:04 PM   #19
enteptain
LQ Newbie
 
Registered: Aug 2011
Location: Louisville,Ky
Distribution: Ubuntu 10.04
Posts: 18

Rep: Reputation: Disabled
hoping i can find some help here but first wanted to say thanks for the bash and awk scripts guys. handy code
im trying to mod this scrit to put a-z upper and lower case in front of each word in my list.
this is what i've been using to put numbers 1-9999 at the end


perl -e 'while(my $line = <>) { chomp($line); foreach my $i (0000..9999) {printf ("$line%04d\n", $i); }}' wordlist.txt >> wordlistnew.txt

thanks in advance. I'm writing these into a tool
 
Old 08-24-2011, 10:13 PM   #20
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,561

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
As above, please ask your own question and reference here if required as most won't look at old questions, especially SOLVED ones.
 
Old 08-24-2011, 10:19 PM   #21
enteptain
LQ Newbie
 
Registered: Aug 2011
Location: Louisville,Ky
Distribution: Ubuntu 10.04
Posts: 18

Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by grail View Post
As above, please ask your own question and reference here if required as most won't look at old questions, especially SOLVED ones.
okay! thanks for the lighting reply speed!!!
 
Old 02-12-2012, 06:22 PM   #22
sapto
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Rep: Reputation: Disabled
The output file format in .txt can be very large. Is it possible to, for example, after 100 mb, creates a new output files also in .txt?
 
Old 02-12-2012, 09:15 PM   #23
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,135

Rep: Reputation: 299Reputation: 299Reputation: 299
Quote:
Originally Posted by Kenhelm View Post
Code:
 grep -Ev '(.)\1'
It was easy to adapt this clever grep to read a long list of English words and keep only those which contain one or more letter pairs (such as the word letter).
Code:
grep -E '(.)\1' < $InFile > $Work02
Now I want to extend the theme to keep only those words which contain two or more letter pairs (such as the word success). I tried this ...
Code:
grep -E '/(.).*(.)/\1 2' < $InFile > $Work03
... but that generates an empty file.

Daniel B. Martin
 
Old 02-12-2012, 10:00 PM   #24
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,151

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Try egrep '(.)\1+.*(.)\2+' $InFile > $Work03

An example:
Code:
$ echo -e success\\ntest\\n | egrep '(.)\1+.*(.)\2+'
success
 
1 members found this post helpful.
Old 02-13-2012, 06:14 AM   #25
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Quote:
Originally Posted by sapto View Post
The output file format in .txt can be very large. Is it possible to, for example, after 100 mb, creates a new output files also in .txt?
Instead of redirecting to a file, try piping to split:

Code:
clisp clisptxt | split -d -b $(CHUNK_SIZE_IN_BYTES) - $(FILE_NAME_PREFIX)
Though again this could have gone into its own thread.

Hope this helps,
 
Old 02-13-2012, 06:52 AM   #26
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,135

Rep: Reputation: 299Reputation: 299Reputation: 299
Quote:
Originally Posted by PTrenholme View Post
Try egrep '(.)\1+.*(.)\2+' $InFile > $Work03
Lovely, works like a charm! Thank you.

It was an easy matter to extend this one-liner to ...
(1) build a list of all words with three letter pairs (such as the word committee).
Code:
egrep '(.)\1+.*(.)\2+.*(.)\3+' < $InFile > $Work04
... and (2) build a list of all words with three consecutive letter pairs (such as the word bookkeeper).
Code:
egrep '(.)\1+(.)\2+(.)\3+' < $InFile > $Work05
On what basis does technical intuition guide you toward egrep rather than grep?

Daniel B. Martin
 
Old 02-13-2012, 07:30 AM   #27
sapto
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Rep: Reputation: Disabled
Quote:
Originally Posted by Snark1994 View Post
Instead of redirecting to a file, try piping to split:

Code:
clisp clisptxt | split -d -b $(CHUNK_SIZE_IN_BYTES) - $(FILE_NAME_PREFIX)
Though again this could have gone into its own thread.

Hope this helps,
I need only .txt format for aircrack...thanks a lot
 
Old 02-13-2012, 10:44 AM   #28
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,151

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Quote:
Originally Posted by danielbmartin View Post
Lovely, works like a charm! Thank you.

It was an easy matter to extend this one-liner to ...
(1) build a list of all words with three letter pairs (such as the word committee).
Code:
egrep '(.)\1+.*(.)\2+.*(.)\3+' < $InFile > $Work04
... and (2) build a list of all words with three consecutive letter pairs (such as the word bookkeeper).
Code:
egrep '(.)\1+(.)\2+(.)\3+' < $InFile > $Work05
On what basis does technical intuition guide you toward egrep rather than grep?

Daniel B. Martin
  1. The "<" in the command is both unnecessary and a waste of resources. grep reads all arguments after the first one (the regular expression) as input file names.
  2. egrep is just a standard alias for grep -e

Last edited by PTrenholme; 02-13-2012 at 10:51 AM. Reason: Unneeded comments deleted.
 
1 members found this post helpful.
Old 02-13-2012, 09:13 PM   #29
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,491

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Quote:
Originally Posted by PTrenholme View Post
egrep is just a standard alias for grep -E
Fixed that for you.
 
Old 08-17-2013, 10:35 AM   #30
albanese
LQ Newbie
 
Registered: Aug 2013
Posts: 1

Rep: Reputation: Disabled
Smile how to save to a file txt

how to save to a file txt
 
  


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
LXer: Comparing Kernel Dmesgs: Remove Timing Info and Diff Side by Side LXer Syndicated Linux News 0 08-04-2010 07:31 PM
X11 and TEXT mode dual monitor side by side marius_c Linux - General 0 10-30-2009 10:30 AM
Installing SUSE 11.1 side by side with Ubuntu already installed on a USB drive jjchavez Linux - Laptop and Netbook 2 09-12-2009 01:39 PM
LXer: Top Linux photo managers side-by-side LXer Syndicated Linux News 0 12-14-2006 06:33 PM


All times are GMT -5. The time now is 11:32 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration