LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-21-2019, 03:08 PM   #1
panorain
Member
 
Registered: Dec 2018
Location: North Pole
Distribution: LinuxMint 19.1 Mate Desktop/
Posts: 51

Rep: Reputation: Disabled
Is there a way to completely revert a 'sed' command?


I have installed LinuxMint 19.1 Mate 64 Bit edition on my computer.

I have issued the following command: ----> sed -i 's/wifi.powersave = 3/wifi.powersave = 2/'

I did powercycle/reboot the pc.

The command does in fact help the Ralink rt61 pci wireless card stay connected wirelessly and not constantly drop the wireless signal.

The problem is when I suspend the computer and then unsuspend the computer 'Network Manager' show's a 'disconnected' icon in taskbar even while it is not disconnected.

I am still able to Ping and use the webbrowser after unsuspend which is great.

1. How can I revert/remove effect of command: sed -i 's/wifi.powersave = 3/wifi.powersave = 2/'

2. I have found that command: sudo sed -i 's/3/2/' /etc/NetworkManager/conf.d/*
After suspend/unsuspend does not break the Mate Network Manager task icon or ability to modify Network Manager settings. Testing on a different PC.

Thanks
 
Old 01-21-2019, 03:20 PM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,392

Rep: Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624
The opposite of
Code:
sed -i 's/wifi.powersave = 3/wifi.powersave = 2/'
is
Code:
sed -i 's/wifi.powersave = 2/wifi.powersave = 3/'
E.g. run it on all files in /etc/NetworkManager/
Code:
sudo sed -i 's/wifi.powersave = 2/wifi.powersave = 3/' /etc/NetworkManager/conf.d/*
Will edit all the files i.e. change their dates even if nothing matched and the contents is not changed.
 
1 members found this post helpful.
Old 01-21-2019, 05:10 PM   #3
panorain
Member
 
Registered: Dec 2018
Location: North Pole
Distribution: LinuxMint 19.1 Mate Desktop/
Posts: 51

Original Poster
Rep: Reputation: Disabled
@MadeInGermany

Thank You for your reply that makes sense actually.

1. Do you happen to know why after suspend/unsuspend of the computer 'Network Manager' appears disconnected even while it is not disconnected? I can still ping an address and use Internet browser.

2. Do you know if it is recommended or better to maintain wireless connectivity to use the following command:
Code:
sudo iwconfig interface/device name power off
Thanks again.

Last edited by panorain; 01-21-2019 at 05:46 PM. Reason: Wording
 
Old 01-21-2019, 11:34 PM   #4
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,828
Blog Entries: 3

Rep: Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398
About the -i option, if you add something after it, a backup file will be made with that string appended to it.

Code:
sed -i.orig 's/old/new/g; /etc/some/files*'
Then you can use cp to copy the backup file(s) over the modified file(s) when you need to restore quickly.
 
Old 01-22-2019, 12:24 AM   #5
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 4,789

Rep: Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425
Quote:
Originally Posted by MadeInGermany View Post
The opposite of
Code:
sed -i 's/wifi.powersave = 3/wifi.powersave = 2/'
is
Code:
sed -i 's/wifi.powersave = 2/wifi.powersave = 3/'
Strictly speaking, the second command does not restore the original content. If there were several wifi.powersave lines originally, some with a value of 2, others with 3, the first command would turn them all into 2, and the second command into 3. The original could not be recovered without a backup.

In this specific case, it may well be the solution, though.
 
Old 01-22-2019, 02:17 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 14,633

Rep: Reputation: 4759Reputation: 4759Reputation: 4759Reputation: 4759Reputation: 4759Reputation: 4759Reputation: 4759Reputation: 4759Reputation: 4759Reputation: 4759Reputation: 4759
Yes, as it was mentioned you are not able to revert any sed commands. The only [safe] way to restore the original version is to use a backup. Either by using
Code:
sed -i<backup> 'script' filename
# or 
sed 'script' source > dest
Personally I would never use -i.
 
1 members found this post helpful.
Old 01-22-2019, 03:40 AM   #7
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 288Reputation: 288Reputation: 288
Quote:
Originally Posted by panorain View Post
1. How can I revert/remove effect of command: sed -i 's/wifi.powersave = 3/wifi.powersave = 2/'
2. I have found that command: sudo sed -i 's/3/2/' /etc/NetworkManager/conf.d/*
Those exact sentences really give me the impression that you don't fully understand how sed works.
There is no problem with that, I mean you can perfectly look for information on the internet/man pages...
The real problem IMHO is that you should never run commands grabbed from some place on your system that you don't really understand. See the last 2 items of my sig. You have no idea the damages that can be done this way...

Last edited by l0f4r0; 01-22-2019 at 03:42 AM.
 
Old 01-22-2019, 04:21 PM   #8
jeremy31
LQ Newbie
 
Registered: Dec 2018
Distribution: Linux Mint 19 Ubuntu 18.04
Posts: 21

Rep: Reputation: Disabled
panorain, it may be easier to create a systemd service that restarts Network Manager after resume or deal with the issue that Network Manager shows disconnected when it isn't
 
  


Reply

Tags
network manager, ralink, sed, wifi, wireless


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Best way to revert to an older kernel on Slackware-current? Miranden Slackware 10 09-20-2013 10:05 AM
[SOLVED] I want to revert a command magankr Red Hat 3 08-21-2012 07:14 PM
Slackware-current: Is there any way to *completely* get rid of Xinerama? folkenfanel Slackware 1 01-12-2011 01:50 PM
[SOLVED] xen revert to snapshot from command line genderbender Linux - Virtualization and Cloud 1 11-01-2010 12:39 PM
iptables command to revert to dropping after an app closes? conn-fused Linux - Security 3 02-24-2007 12:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration