Monday, January 30, 2017

Regexp replace until space sed regular expression

I asked my collegues how to replace until next space with sed.
They solved it for me.
sed -i 's/password=[^[:space:]]*/password=geenpassword/g' test.txt

I had to blog this excellent answer.
Thanks to Danny and Frank for solving this.

Btw.
I used awk for this.
But that was not the sed solution.


{for (i=1; i <= NF; i++) { if ($i !~ /password/) {printf($i" ") ;}
                           else {printf("GEHEIM ")}if(i==NF){printf("\n")}}}