Bash 如何使用shell脚本替换具有字符的行中的单词

Bash 如何使用shell脚本替换具有字符的行中的单词,bash,shell,Bash,Shell,我有一个文件,它的内容是这样的 #Time value 2.5e-5 1.3 5e-5 2.7 7.5e-5 1.1 0.0001 5.9 0.000125 5.8 0.00015 3 ...... 我怎样才能用科学符号替换其中带有字母e的行,以便最终文件 #Time value 0.000025 1.3 0.00005 2.7 0.000075 1.1 0.0001 5.9 0.000125 5.8 0.00015 3 ...... shell脚本能够做到这一点吗 for (any wo

我有一个文件,它的内容是这样的

#Time value
2.5e-5 1.3
5e-5 2.7
7.5e-5 1.1
0.0001 5.9
0.000125 5.8
0.00015 3
......
我怎样才能用科学符号替换其中带有字母e的行,以便最终文件

#Time value
0.000025 1.3
0.00005 2.7
0.000075 1.1
0.0001 5.9
0.000125 5.8
0.00015 3
...... 
shell脚本能够做到这一点吗

for (any word that is using scientific notation)
{
    replace this word with decimal notation
}

如果您熟悉C中的函数,则有一个类似的内置shell命令:

$ printf '%f' 2.5e-5
0.000025
$ printf '%f' 5e-5
0.000050
要在脚本中使用此选项,可以执行以下操作:

while read line; do
    if [[ $line = \#* ]]; then
        echo "$line"
    else
        printf '%f ' $line
        echo
    fi
done < times.txt

如果您熟悉C中的函数,则有一个类似的内置shell命令:

$ printf '%f' 2.5e-5
0.000025
$ printf '%f' 5e-5
0.000050
要在脚本中使用此选项,可以执行以下操作:

while read line; do
    if [[ $line = \#* ]]; then
        echo "$line"
    else
        printf '%f ' $line
        echo
    fi
done < times.txt
使用awk:

使用awk:


好的,但是如何找到哪一行和哪一个单词包含e并进行打印呢?@Daniel你可以很容易地用awk进行打印。好的,但是如何找到哪一行和哪一个单词包含e并进行打印呢?@Daniel你可以很容易地用awk进行打印。