Text Manipulation Help

Hello again unix.com,

I have a text file in this format (line-by-line):

hostname id password
hostname id password
hostname id password
hostname id password

I want it to become:

hostname id password
hostname id password
hostname id password
hostname id password
hostname:25:id:password:
hostname:25:id:password:
hostname:25:id:password:
hostname:25:id:password:

Is there a way I can manipulate all instances in the list?

Thanks!

Any attempts/ideas/thoughts from your side?

Anyhow, try

awk '($2="25" OFS $2) && $NF=$NF OFS' OFS=":" file
hostname:25:id:password:
hostname:25:id:password:
hostname:25:id:password:
hostname:25:id:password:
1 Like

Well I dont know sed that well... I know only replace but stuck with adding :smiley:

sed 's/ /:/g' file >> newfile

This is for replacing spaces with ":' (i think) only but for rest.. i need a little help :smiley:

---------- Post updated at 02:38 PM ---------- Previous update was at 02:37 PM ----------

And yes... still looks like egyptian hieroglyphs but I'm in the learning phase :smiley:

Thank you.

Should you insist on sed :

sed 's/ / 25 /;s/ \|$/:/g' file
hostname:25:id:password:
.
.
.
1 Like