user2306367
user2306367

Reputation: 1

how to insert a word in text file using shell script

Can any one please help me for below problem

I have a text file in below format and i want to insert a word in a specific field and i want to save that file in shell script with out disturb any thing in the file.

Ex:

cat sample.txt

name=xxxxxx

age=45

gender=femal

college=XXXXXX

class=b1

section=h2

like that

I want to insert in place of XXXXX some word.

Is it possible or not ?

Upvotes: 0

Views: 2413

Answers (2)

Zombo
Zombo

Reputation: 1

Another option

sed -i '/^college=/ccollege=some word' sample.txt

Result

name=xxxxxx

age=45

gender=femal

college=some word

class=b1

section=h2

Upvotes: 0

Razvan
Razvan

Reputation: 2596

sed -i 's/college=.*/college=SOME WORD/' sample.txt

Upvotes: 1

Related Questions