0

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.

kirikoumath
  • 723
  • 9
  • 20

4 Answers4

1
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)

Alp
  • 3,027
  • 1
  • 13
  • 28
1

If you want to replace strings in file: https://unix.stackexchange.com/questions/112023/how-can-i-replace-a-string-in-a-files

If you ant to rename files in folder: Using sed to mass rename files

Community
  • 1
  • 1
Ritesh
  • 1,809
  • 1
  • 14
  • 16
0
$ line='result_0.01.dat resultFile'
$ echo "$line" | sed 's/result_0.01/different text which might include numbers/'
different text which might include numbers.dat resultFile
John1024
  • 109,961
  • 14
  • 137
  • 171
0
echo result_0.01.dat | sed 's/result_0.01/123456/g'

will replace the resulat_0.01 with 123456 using sed.

So in general you can use it like this: sed 's/PATTERN-YOU-WANT-TO-REPLACE/REPLACE-IT-WITH/g'.

cjhveal
  • 5,668
  • 2
  • 28
  • 38
joni
  • 6,840
  • 2
  • 13
  • 20