Sponsored Content
Top Forums UNIX for Dummies Questions & Answers UNIX BASH replace char with dash w/o SED Post 302561664 by needsomehelp on Tuesday 4th of October 2011 10:06:54 PM
Old 10-04-2011
Thanks for the suggestion. I was not able to implement your suggestion into my coding. It may be due to the way I have my code set up. Here is the function I created:
Code:
function yesSelected()
{
local word=$(randomWord)
local count=0
local countChar=0
local correctWord="n"
local chars
local attempts=10
local display
local charLower




        clear
        while [[ $correctWord = "n" && $count -lt $attempts ]]
        do
        echo $word
        gameDisplay $count $countChar $display $chars
        echo
        read -p "Please enter a character: " char
        charLower=$(echo "$char" | tr [A-Z] [a-z] )
        (( countChar=countChar + 1 ))
        if [[ "$(letterValid $charLower)" -eq 0 ]]
        then
          if [[ $chars =~ .*$charLower.* ]]
          then
          clear
          charUsed
          else
            chars="${chars}${charLower}"
            if [[ $word =~ .*$charLower.* ]]
            then
                ((count = count))
              else
                ((count = count + 1))
            fi
              display=$(echo "$word" | sed "s/[^${chars}]/-/g")
            clear
            if [ $word = $display ]
            then
              correctWord="y"
              clear
            fi
          fi
        else
          clear
          invalidErrorMessage
        fi
        done
        if [[ $count -eq 10  ]]
        then
          echo "SORRY. The word was $word."
          echo
          tooManyAttempts
          echo
          gameEnded
          else
                congratsScreen
                gameEnded
          fi
}

yesSelected

I pass in a "randomWord" from another function and then use it to perform the task. I am trying not to use SED in my program so I wanted to see if there is another way to get the same result.

Thanks again for your help in this matter.

Last edited by vbe; 10-05-2011 at 11:21 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace any char with newline char.

Hi, How to replace any character in a file with a newline character using sed .. Ex: To replace ',' with newline Input: abcd,efgh,ijkl,mnop Output: abcd efgh ijkl mnop Thnx in advance. Regards, Sasidhar (5 Replies)
Discussion started by: mightysam
5 Replies

2. UNIX for Dummies Questions & Answers

Unix script, sed search and replace?

Hi, I am trying to write a shell script designed to take input line by line by line from a file with a word on each line for editing with sed. Example file: 1.ejverything 2.bllown 3.maikling 4.manegement 5.existjing 6.systems My design currently takes input from the user, and... (2 Replies)
Discussion started by: mkfitzwilliams
2 Replies

3. Shell Programming and Scripting

SED: Place char at starting and replace selected line

Hello Experts, I am working on a small file editing script. Since all experts here are very generous to give me the complete code, I would take up the problem in steps so that I ensure my opportunity to learn. AIM: The script has some commented and some uncommented lines. I need to : ... (2 Replies)
Discussion started by: hkansal
2 Replies

4. Shell Programming and Scripting

Bash sed search and replace question

I have several files that I need to modify using sed. I know how to do that, but now a new requirement has come up. Now, I need to make changes to all lines that don't start with certain strings. For example, I need to change all lines except for lines that start with "a", "hello there",... (3 Replies)
Discussion started by: RickS
3 Replies

5. Shell Programming and Scripting

Replace last row of a column in bash/awk/sed

Hi, I've got a file with 3 columns which ends like this: ... 1234 345 1400 5287 733 1400 8472 874 1400 9317 726 1400 I want to replace the last row of the last column with the value 0. So my new file will end: ... 1234 345 1400 5287 733 1400 8472 874 1400 9317 726 ... (5 Replies)
Discussion started by: jhunter87
5 Replies

6. Shell Programming and Scripting

Bash: using SED, trying to replace some characters except first or last line

Hi, I require to replace 2 items: 1. replace start of all lines in a file with ' except the first line 2. replace end of all lines in a file with '||chr( except last line I am able to do the entire file using sed -e s/^/\'/g -e s/$/\'\|\|chr\(/g "$file" > newfile.txt but am not yet able... (0 Replies)
Discussion started by: Chella15
0 Replies

7. UNIX for Dummies Questions & Answers

Bash: using SED, trying to replace some characters except first or last line

Hi, I require to replace 2 items: 1. replace start of all lines in a file with ' except the first line 2. replace end of all lines in a file with '||chr( except last line I am able to do the entire file using sed -e s/^/\'/g -e s/$/\'\|\|chr\(/g "$file" > newfile.txt but am not yet... (3 Replies)
Discussion started by: Chella15
3 Replies

8. Shell Programming and Scripting

Using sed command replace date variable in unix

I need to use a shell script, using sed command how to replace date variable value in following format. 04/18/2012 11:38:55 Because the sed is treating the '/' as a parameter instead of the value of a variable, and hence there is the message as sed: command garbled: s/insert/04/18/2012... (9 Replies)
Discussion started by: jannusuresh
9 Replies

9. UNIX for Beginners Questions & Answers

Views How to replace a CRLF char from a variable length file in the middle of a string in UNIX?

My sample file is variable length, with out any field delimiters. It has min of 18 chars length and the 'CRLF' is potentially between 12-14 chars. How do I replace this with a space? I still want to keep end of record, but just want to remove these new lines chars in the middle of the data. ... (7 Replies)
Discussion started by: chandrath
7 Replies

10. UNIX for Advanced & Expert Users

Replace \n char in Data

File is pipe delimited with 17 fields. We may get \n char (1 or more \n in one field or multi fileds) in data in any field. Need to replace \n in data with space and not the Ture \n that is line separator. I tried below awk command it did not work as expected. awk '(NR-1)%2{$1=$1}1' RS=\|... (9 Replies)
Discussion started by: rajeshkumare
9 Replies
TPING(1)							   LAM COMMANDS 							  TPING(1)

NAME
tping - Send echo messages to LAM nodes. SYNOPSIS
tping [-hv] [-c count] [-d delay] [-l length] nodes OPTIONS
-h Print the command help menu. -v Turn OFF verbose mode. -c count Send count messages. -d delay Delay delay seconds between each message. -l length Each message is length bytes long. DESCRIPTION
The tping command sends messages to, and collects replies from, a list of nodes, via the LAM echo server. It is similar to the UNIX ping(8) command, and is used as a quick diagnosis of the LAM network. Unless options are specified, tping sends a 1 byte message an infinite number of times, displaying the roundtrip time of each message as it completes, with a delay of 1 second between roundtrips. After the loop is broken (with keyboard interrupt, eg: ^C), tping prints statis- tics about all roundtrip messages. EXAMPLES
tping h Echo messages to the local node. tping -v n7 -l 1000 -c 10 Echo 1000 byte messages to node 7. Stay silent while working. Stop after 10 roundtrips and report statistics. BUGS
There is no built-in timeout and tping will wait forever to receive an echo. If no echo is received, due to a dead link or node, tping hangs. Stop the process with a keyboard suspend signal (eg: ^Z) and terminate LAM with lamhalt(1) or lamwipe(1) (although the use of lamwipe(1) is deprecated). SEE ALSO
lamhalt(1), lamwipe(1) LAM 7.1.4 July, 2007 TPING(1)
All times are GMT -4. The time now is 03:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy