Read a file and modify it

DikongPrigm

New Member
Joined
Dec 8, 2022
Messages
4
Reaction score
0
Credits
33
Hello, I just want to ask some help as I am new to Linux. Basically I just want to modify the appversion and version number of this file. This is the content of the file.
I would like to change it to

version: 2.0.0-alpha.4.0-XXXXX
appVersion="2.0.0-alpha.4.0-XXXXX"
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 2.0.0-alpha.4.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "2.0.0-alpha.4.0"
 


sed is what I'm trying to use together with grep but I'm having a hard time doing it.
What I have in mind is to get the work "appVersion: 2.0.0-alpha.4.0", split this and just get only the version without quotation mark, modify it and then search the file with the text that contains this version and replace them all.
 
Last edited:
There are sooo many ways to do that on linux. Since you are new to linux, i would recommend getting familiar with nano. Since you seem to also be a developer or something, i also think familiarity with vim is nice, but you can learn all the ins and outs of nano in a couple of days (including using the .nanorc file to make changes to the program), whereas vim will take you at least 10 hours to get comfortable with.

However you can also do exactly this with sed, but be VERY careful, as sed can make dramatic changes to a document. Use these two commands:

Code:
sed 's/2.0.0-alpha.4.0/2.0.0-alpha.4.0-XXXXX/' <file>

sed 's/"2.0.0-alpha.4.0"/"2.0.0-alpha.4.0-XXXXX"/' <file>

once you are comfortable with the output (sed doesn't change files but just displays it in your terminal), then you can do this to make the permanent changes:

Code:
sed -i 's/2.0.0-alpha.4.0/2.0.0-alpha.4.0-XXXXX/' <file>



sed -i 's/"2.0.0-alpha.4.0"/"2.0.0-alpha.4.0-XXXXX"/' <file>
 
sed is what I'm trying to use together with grep
grep is basically just a way to search the contents of text files in linux, very handy...you should use my script:

Code:
#!/bin/bash
#this will look through every file in a working directory and
#find the text files that contain certain text
read -p "Display text files that contain what? " term

grep -lIs "$term" *
#options mean show files containing text of file, omit binary files,
#omit error messages
 
There are sooo many ways to do that on linux. Since you are new to linux, i would recommend getting familiar with nano. Since you seem to also be a developer or something, i also think familiarity with vim is nice, but you can learn all the ins and outs of nano in a couple of days (including using the .nanorc file to make changes to the program), whereas vim will take you at least 10 hours to get comfortable with.

However you can also do exactly this with sed, but be VERY careful, as sed can make dramatic changes to a document. Use these two commands:

Code:
sed 's/2.0.0-alpha.4.0/2.0.0-alpha.4.0-XXXXX/' <file>

sed 's/"2.0.0-alpha.4.0"/"2.0.0-alpha.4.0-XXXXX"/' <file>

once you are comfortable with the output (sed doesn't change files but just displays it in your terminal), then you can do this to make the permanent changes:

Code:
sed -i 's/2.0.0-alpha.4.0/2.0.0-alpha.4.0-XXXXX/' <file>



sed -i 's/"2.0.0-alpha.4.0"/"2.0.0-alpha.4.0-XXXXX"/' <file>
I initially dont know what the version should be. I should search it within the file and update it with my desired version
 

Members online


Top