Skip to content
Advertisement

grep the filename using sed

I have the following line

result_0.01.dat resultFile

I would like to get and change just the (result_0.01) part to a different text which might include numbers. Preferably I would like this to be done using sed.

Thank you in advance.

Advertisement

Answer

echo "result_0.01.dat resultFile" | sed  "s|.*.dat|someOtherText.dat|g"

what happens here in sed part is:

we substitude (s flag at the beginning of sed) we find everything till .dat. We replace that part with someOtherText. and we do it globally (g flag at the end)

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement