How to get grep output in one line in shell script?

Here is a script that reads the words from the replace.txt file and displays the output of each word in each line, but I want to display all the outputs in one line.

#! / bin / sh
 echo
 echo "Enter the word to be translated"
 read a
IFS = "" # Set the field separator
set $ a # Breaks the string into $ 1, $ 2, ...
for a # a for loop by default loop through $ 1, $ 2, ...
    do
    {
    b = grep "$ a" replaced.txt | cut -f 2 -d ""
    }
    done 

The contents of the file "replace.txt" is shown below:

hllo HELLO
m AM
rshbh rishabh
jn jain
hw how 
ws was 
ur YOUR
dy DAY

This question is not suitable for what I asked, I just need help to output the script output on one line.

+5
3

script :

#!/bin/bash
echo
read -r -p "Enter the words to be translated: " a
echo $(printf "%s\n" $a | grep -Ff - replaced.txt | cut -f 2 -d ' ')

.

echo / .

+9

, - printf %s "$(...) ". :

b= grep "$a" replaced.txt | cut -f 2 -d" "

:

printf %s "$(grep "$a" replaced.txt | cut -f 2 -d" ") "

echo .

$(...) " ": grep "$a" replaced.txt | cut -f 2 -d" " , , , . , , DAY, :

printf %s "DAY "

( printf %s ... echo -n ... — — , , , , -n -e -.)

+2

You can also use

awk 'BEGIN { OFS=": "; ORS=" "; } NF >= 2 { print $2; }'

in the pipe after the cut.

+1
source

All Articles