Random letters


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Random letters
# 8  
Old 08-23-2018
Set the output field separator to <TAB>: OFS="\t" just before the file name.
The non-substitution was possibly due to several factors:
- a three char word would offer few options to subst; in fact, we would have one single substitution only, when going for LEN/2 chars.
- the rand() function can return a zero value, so none of the string's characters (1 - LEN) were targeted.



Try
Code:
awk -F"\t" '
        {LEN = split ($2, T, "")
         $2 = ""
         for (i=1; i<=(LEN+1)/2; i++) T[int(.5+rand()*LEN)] = " _ "
         for (i=1; i<=LEN;       i++) $2 = $2 T[i]
        }
1
' OFS="\t" file


Last edited by RudiC; 08-23-2018 at 06:48 AM..
# 9  
Old 08-23-2018
Worked like magic!

------ Post updated at 04:51 AM ------

Final result: approx 1200 words didn't come out with any letter blanked out out of a total of 48k. I can't see any patterns or similarities in them.
# 10  
Old 08-23-2018
Again, facts, please. Does it happen again / identical to the same words on a second run?
# 11  
Old 08-23-2018
Screenshot

Yes, always the same words.
Random letters-blanked-out2png

Last edited by eldeingles; 08-23-2018 at 07:16 AM..
# 12  
Old 08-23-2018
Files

Here is the non-blanked out words file.
# 13  
Old 08-23-2018
Extract a few of the offending lines into a small file and run the script several times - there should be varying substitutions; at least there are when I do.

As said in the beginning - it's an approximation to be refined if further conditions need to be met.
# 14  
Old 08-23-2018
Yes, the offending lines become less numerous as I run the code and process again the resulting lines. It works perfect for me!

Thanks again RudiC!

Shall we close the thread?

------ Post updated at 05:48 AM ------

It took me 9 rounds. The final 2 rounds consisted of 3-letter words and a very few 2-word.
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