Random letters


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Random letters
# 1  
Old 08-23-2018
Random letters

Hi there,
first of all this is not homework...this is a new type of exercise for practicing vocabulary with my students.
I have a file consisting of two columns, separated by a tab, each line consisting of a word and its definition, separated by a line break.

What i need is to replace a number of random letters of the defined word with an underscore. The number of letters would depend on the length of the word, but half its number would be ok...ideas?

Much appreciated.
# 2  
Old 08-23-2018
An input sample, and a desired output would help.
# 3  
Old 08-23-2018
INPUTFILE


a true … of Islam \t follower
the recent … of two CIA agents \t disappearance
The restructuring is designed to give a sharper … on key markets. \t focus
a large country house with beautiful landscaped … \t gardens


OUTPUTFILE

a true … of Islam \t fo _ _o_er
the recent … of two CIA agents \t d_ _a_ _ear_ _ce
The restructuring is designed to give a sharper … on key markets. \t f_ c_s
a large country house with beautiful landscaped … \t _ar_e_s
# 4  
Old 08-23-2018
zeroth approximation .. you need to eliminate the leading spaces in $2, no check is done to not to replace an already set "_" with another one, nor replacement of adjacent characters. Try



Code:
awk -F"\t" '
        {LEN = split ($2, T, "")
         $2 = ""
         for (i=1; i<=LEN/2; i++) T[int(rand()*LEN)] = "_"
         for (i=1; i<=LEN;   i++) $2 = $2 T[i]
        }
1
' file
a true … of Islam  fol__w_r
the recent … of two CIA agents  di_app_a___ce
The restructuring is designed to give a sharper … on key markets.  f_c_s
a large country house with beautiful landscaped …  ___de_s

These 2 Users Gave Thanks to RudiC For This Post:
# 5  
Old 08-23-2018
Wow, RudiC, that's awesome!
A final thought: how could I add a blank space when 2 underscores are together?

Great help!

------ Post updated at 03:40 AM ------

Forget it! I figured it out myself.

------ Post updated at 03:51 AM ------

How could I get the blanked_out resulting word separated from the definition by a tab? This I can't figure it out.

------ Post updated at 04:01 AM ------

For some reason this words didn't come out well:
- ...
- footprints left in the hard dried ... mud
- ...
- a hit TV ... show
- ...
- a blanket advertising ... on tobacco ban
- I need my beauty ... . rest
- Elephants have a very tough ... . hide
# 6  
Old 08-23-2018
Facts / data, please.
Where exactly do you need the <TAB> separation?
What and how "didn't come out well"?


For the space separated underscore chars, use " _ " for the T[...] assignment.
# 7  
Old 08-23-2018
That's what I would need to be incorporated into an Excel sheet.

Code:
A ransom ... has been made for the kidnapped racehorse.  \t _  _ m _ nd

Code:
A third of the country's population is of mixed racial ... . \t h _ ri _  _  _ e

Code:
the professional ... of the lawyers and accountants involved  \t _ ees


And the words that didn't come out well is because none of their letters were substituted by any blank.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to cut only letters?

I was wondering how I could cut only the names of items from the following list: spoons50 cups29 forks50 plates29 I used "man cut" and thought -c would help, but the items have different character lengths. Please note that there is no space between the item and number (so I can't use... (10 Replies)
Discussion started by: PTcharger
10 Replies

2. Shell Programming and Scripting

Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom. I create a named pipe then: dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024 but when I cat a file to the fifo that's 1024 random bytes: cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies

3. Shell Programming and Scripting

Randomize letters

Hi, Is there a tool somewhat parallel to rev, but which randomizes instead of reverses? I've tried rl, but I can only get it to randomize words. I was hoping for something like this echo "hello" | ran leolh less simpler solutions are also welcome. Sorry if the question is... (21 Replies)
Discussion started by: jeppe83
21 Replies

4. Ubuntu

Random insertion of letters to password

Hi,, Here i have attached a text file where iam facing problem in my code. Please read the file and help me out of this issue.. Thanks in advance (4 Replies)
Discussion started by: vanid
4 Replies

5. Ubuntu

expect script for random password and random commands

Hi I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue: I want expect script for random passwords and random commands generation. please can anyone help me? Many Thanks in advance (0 Replies)
Discussion started by: vanid
0 Replies

6. UNIX for Advanced & Expert Users

Add letters

I want to add letters A,B,C,… in front of every line of input while printing them out using PERL. eg A file is parsed as a cmd line arg and its context will be displayed as A line1... B line 2.. I tried this..but I want better and perfect solution! !perl -p my $counter; BEGIN { $counter... (4 Replies)
Discussion started by: aadi_uni
4 Replies

7. Shell Programming and Scripting

Need to strip few letters

Hey guys.. Can experts help me in achieving my purpose.. I have a file which contains email address of some 100 to 1000 domains, I need only the domain names.. Eg: abc@yahoo.com hd@gamil.com ed@hotmail.com The output should contain only Yahoo.com ... (5 Replies)
Discussion started by: achararun
5 Replies

8. Shell Programming and Scripting

trim letters

Hello, I have a list of words.. ranging from 4 to any characters long.. to not more than 20 though. How can I select only first seven letters of the list of words? example:- wwwwwwwwww eeeee wererreetf sdsarddrereewtewt sdsdsds sdsd ereetetttt ewtwertwrttrttrtrtwtrww I... (10 Replies)
Discussion started by: fed.linuxgossip
10 Replies

9. Shell Programming and Scripting

transposing letters

Hi, I've written a shell function in bash that reads letters into an array, then outputs them in one column with: for n in "${array}"; do echo $n done I was wondering if anyone knew how i would transpose the letters that are output by the for loop. Right now my output is: aabbcc... (4 Replies)
Discussion started by: myscsa2004
4 Replies

10. UNIX for Dummies Questions & Answers

capital letters GONE!

I have an odd issue. I am trying to copy some files/folders to my linux box via a burned CD which I created on my mac. When I browse the files on the mac (or my windows box), everything looks fine (some of the folder names start with a capital letter, which is needed for everything to work... (8 Replies)
Discussion started by: blogg
8 Replies
Login or Register to Ask a Question