小编Par*_*ora的帖子

如何在shell脚本中以单行输出grep?

这是一个脚本,它从文件的replace.txt中读取单词并显示每行中每个单词的输出,但我想在一行中显示所有输出.

#!/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 

"replacement.txt"文件的内容如下:

hllo HELLO
m AM
rshbh RISHABH
jn JAIN
hw HOW 
ws WAS 
ur YOUR
dy DAY

这个问题不适合我的问题,我只需要帮助就可以将脚本的输出放在一行中.

bash grep

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

bash ×1

grep ×1