Linux delete spaces after a character in a line

linux, replace, sed

Solution

One way using `awk`:

awk -F# 'OFS=FS { gsub(" ", "+", $2) }1' file.txt

Result:

My Number is = 1234; #This+is+a+random+number

EDIT:

After reading comments below, if your file contains multiple `#`, you can try this:

awk -F# 'OFS=FS { for (i=2; i <= NF; i++) gsub(" ", "+", $i); print }' file.txt

Problem

In Linux, if I have a file with entries like: My Number is = 1234; #This is a random number Can I use sed or anything else to replace all spaces after '#' with '+', so that the output looks like: My Number is = 1234; #This+is+a+random+number

Original source