0

I have a file

versions:
  - sha: 123456789

and now I want to replace the 123456789. Could anybody tell me what I should do to achieve this goal by using bash? Thank you for your help!

Yunxiu Qiu
  • 169
  • 1
  • 2
  • 9
  • 1
    Is this a yaml file? And replace with what? – Shawn Aug 06 '20 at 22:06
  • 1
    do you mean, using only the bash interpreter or you can use typical programs like sed from inside the script ? if it so, you can do sed -i 's/old-text/new-text/g' input.txt – Pablo Yaggi Aug 06 '20 at 22:08
  • @Shawn Yes it is. I just want to replace with a variable (that I would read from git log) – Yunxiu Qiu Aug 06 '20 at 22:12
  • @PabloYaggi Yep I can use sed, but I'm wondering how can I do with indexing? For example in java we can do something like `s.substring(0, 5)`. Because I may not know the number after `sha:` exactly, the `123456789` is just an example. – Yunxiu Qiu Aug 06 '20 at 22:13
  • 1
    use sed with a regular expression that detects the sha you want to replace, can't post a specific answer cause the question is closed. – Pablo Yaggi Aug 06 '20 at 22:18
  • 1
    I strongly suggest using a tool like [yq](https://github.com/kislyuk/yq) that understands the YAML format instead of trying to use regular expressions/sed. – Shawn Aug 06 '20 at 22:22

0 Answers0