简体   繁体   English

在Linux中生成字符串的文本文件

[英]Generating a text file of strings in linux

I need to generate text files of strings of 3 characters, with duplicate strings allowed. 我需要生成3个字符的字符串的文本文件,并允许重复的字符串。 I've searched for a method to do this, but I can only find methods to generate completely random text. 我已经搜索了执行此操作的方法,但是我只能找到生成完全随机文本的方法。 Since I'm still a newbie, I have no idea of how to proceed. 由于我仍然是新手,因此我不知道如何进行。 Any assistance will be greatly appreciated. 任何帮助将不胜感激。

Using bash to get combinations inefficiently: 使用bash无效地获取组合:

a[0]=a; a[1]=b; a[2]=c;
for i in $(seq 0 26); do
  r1=$(expr $i % 3)
  r2=$(expr $i / 3 % 3)
  r3=$(expr $i / 9 % 3)
  echo ${a[$r1]}${a[$r2]}${a[$r3]}
done

A faster way: 更快的方法:

a[0]=a; a[1]=b; a[2]=c;

for r1 in $(seq 0 2); do
  for r2 in $(seq 0 2); do
    for r3 in $(seq 0 2); do
      echo ${a[$r1]}${a[$r2]}${a[$r3]}
    done
  done
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM