OpenWrt Forum Archive

Topic: Help using Sed command Openwrt-nodogsplash.conf

The content of this topic has been archived on 30 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Dear developers,
Need your help with the following:
I want to use the sed command to change a password in a configuration file of nodogsplash.conf

I use this command which work fine.

sed -i 's,Password test4321,Password test1234,' /etc/nodogsplash/nodogsplash.conf

but  the problem is that  command look for a match  of the whole string 'Password test4321' and replace it by 'Password test1234',  but what i need is sed command to replace only the string that is actually the password,
I have tested other sed commands without success.
the problem seems that nodogsplash.conf have several line that start with "Password"
seems that  the sed command need to check for a blank space after Password.
but i have no idea how to do that.
I tested the bellow without success.

sed -i 's/^Password .*$/Password test1234/' /etc/nodogsplash/test.txt

sed -i 's/^Password .*$/Password test1234/' /etc/nodogsplash/nodogsplash.conf

sed -e 's/^\( *Password *\)[^ ]*\(.*\)*$/\1PacMan\2/'  /etc/nodogsplash/nodogsplash.conf

sed -e '/^ *Password / s/ [^# ]/ PacMan45/' /etc/nodogsplash/nodogsplash.conf

thanks for any   help.

(Last edited by luisgcu on 15 Nov 2016, 03:05)

A little bit of Googling that takes you a few minutes would yield the answer as there are many resources on sed regular expressions.

A sed regular expression will match whitespace with a \s.

You could also do it with a character class expression [[:space:]]


sed -ir 's/(^Password\s+)(test4321)/\1test1234/g' /etc/nodogsplash/test.txt
dl12345 wrote:

A little bit of Googling that takes you a few minutes would yield the answer as there are many resources on sed regular expressions.

A sed regular expression will match whitespace with a \s.

You could also do it with a character class expression [[:space:]]


sed -ir 's/(^Password\s+)(test4321)/\1test1234/g' /etc/nodogsplash/test.txt

Hello,
thanks for your answer and time but that instruction didn't do what I need..
the code you posted create an additional file with  a name test.txtr
I did some Googling but i did not find anything
in other words i just want to replace the  Password  which  is located to the right of the string Password  test1234 and the tricky part is changing the password without knowing the current password.. not sure ift its possible with the sed command,
i will continue my googling to see if I find any trick to do that
basically i would need something like te below at first.. then a second instruction to add new string in place of the deleted password.
/////////////////////////////////////////////////////
http://www.grymoire.com/Unix/Sed.html#uh-4a
If you wanted to keep the first word of a line, and delete the rest of the line, mark the important part with the parenthesis:

sed 's/\([a-z]*\).*/\1/'

(Last edited by luisgcu on 16 Nov 2016, 03:57)

How about this?

sed -i 's/\(^.*\)Password \(.*\)/\1Password test1234/g' /etc/nodogsplash/nodogsplash.conf
or
sed -i 's/Password \(.*\)/Password test1234/g' /etc/nodogsplash/nodogsplash.conf
mazilo wrote:

How about this?

sed -i 's/\(^.*\)Password \(.*\)/\1Password test1234/g' /etc/nodogsplash/nodogsplash.conf
or
sed -i 's/Password \(.*\)/Password test1234/g' /etc/nodogsplash/nodogsplash.conf

Thanks you so much.. the first command work perfectly!!
I have to  say thanks to all people that contribute here to the learning of noobs like I am.
thanks guys..

If you just want the sed to replace the whole line with Password test1234, then remove the \1 from \1Password as shown below:

sed -i 's/\(^.*\)Password \(.*\)/Password test1234/g' /etc/nodogsplash/nodogsplash.conf

The discussion might have continued from here.