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 06-14-2007, 07:30 AM   #1
TRJ
LQ Newbie
 
Registered: Jun 2007
Posts: 2

Rep: Reputation: 0
Question Anybody with a word scrambling script ?


Hi guys,

I am trying to write a short script that allows me to read in a word from an input file. I then want to change the character at different positions into various other characters like:

ABCDEFGH #read from input file
#now change character 2 into all other possible
AACDEFGH #output 1
ACCDEFGH #output 2
ADCDEFGH #output 3
etc.

... and then export this new word as a new file (or read it into an executable script). Has anybody a good idea how I could do that. I need to define position as well as the possible characters to change to and write it into a file named with the change.

I am struggeling ... Thanks for your help.

Tom
 
Old 06-15-2007, 12:42 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
What part of this have you written so far? May we see it?
 
Old 06-19-2007, 12:39 PM   #3
atulsvasu
Member
 
Registered: Apr 2006
Distribution: Gentoo
Posts: 49

Rep: Reputation: 15
Hmm.. I don't intend to code, it is very easy..

for(i)
if(i!=1) str[1] = str[i]
 
Old 06-19-2007, 01:56 PM   #4
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by TRJ
Hi guys,

I am trying to write a short script that allows me to read in a word from an input file. I then want to change the character at different positions into various other characters like:

ABCDEFGH #read from input file
#now change character 2 into all other possible
AACDEFGH #output 1
ACCDEFGH #output 2
ADCDEFGH #output 3
etc.

... and then export this new word as a new file (or read it into an executable script). Has anybody a good idea how I could do that. I need to define position as well as the possible characters to change to and write it into a file named with the change.

This should get you started:

Code:
letters="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
read word
right=${word#??}
left=${word%?"$right"}
for l in $letters
do
  printf "%s\n" "$left$l$right"
done
 
Old 06-20-2007, 02:40 AM   #5
TRJ
LQ Newbie
 
Registered: Jun 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Cheers guys, I think that will sort me out for the start. I have started to play around with my scripting skills (i.e. not very much so far) and it runs for a start. Not quite what intended, but at least I am on my way. T.
 
Old 06-20-2007, 08:32 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
are you using bash?
you can do stuff like this...

Code:
$ echo here,{A,B,C,D,E},there
here,A,there here,B,there here,C,there here,D,there here,E,there
 
  


Reply



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
PHP Script to parse Word/RTF Documents saravanan1979 Programming 10 02-18-2010 07:25 AM
search a file for a word - bash script paul_mat Linux - Software 12 04-16-2006 01:59 AM
tcsh script, replace word in file true_atlantis Programming 10 02-17-2006 01:24 PM
a command/script for replacing a word with another jaakkop Programming 14 12-04-2005 10:21 AM
YaST freezes, scrambling filesystem Pingus SUSE / openSUSE 1 12-20-2004 12:16 PM

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

All times are GMT -5. The time now is 03:10 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