Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Bash versus pinyin

    I am a newbie. I am trying my hand at Bash scripting. I have a file with lots of pinyin, which is the romanized version of Chinese characters and words. A typical entry looks like this,

    "7 shuo1 说 to speak"

    Seven is the number of the entry shuo is the pinyin, 1 is the tone mark and 说 is the Chinese character.
    What I would like to do is change the format so that it looks more like this:

    7 shuo 1 说

    Each field needs to be re-assigned to a variable in an array and then printed to the screen and saved to a file in the same order it was input. This is to prepare the data for another project I am working on in imagemagick.
    I have spent all day looking at linux man pages and have very little to show for my efforts. Could someone point me in the right direction. What is the best way to approach this? grep, awk, sed...?

  2. #2

    change of plans

    Okay, no one could help me so, I changed my approach and made it into a data entry
    program instead. What I am having trouble with now is how to limit the input to each question to the appropriate character classes. Right now as the program exists below you can type anything as an answer to a question. I would like to limit the answers and re-prompt if it is not in the correct range. Which commands should I be looking at to implement this? I just need someone to point me in the right direction.

    # make executable by typing chmod +x
    # run program with ./
    # This is a data entry program for formatting Hanzi/Pinyin
    read -p "Please enter a Hanzi character: " H
    echo -n "Tone number (1-4)"
    read -n 1 T
    read -p "Please enter the corresponding PinYin: " P
    read -p "Please enter a short definition entry: " D
    echo $H $P $T $D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts