LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-27-2011, 10:25 AM   #1
merana
Member
 
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 80

Rep: Reputation: 15
Strange sed results


Hi Everyone.

Long time since I posted... I have an odd issue that I am running into. My objective is to insert the following lines at the end of /etc/inputrc on an RHES box:

Code:
# alternate mappings for "page up" and "page down" to search the history
"\e[5~": history-search-backward
"\e[6~": history-search-forward
I would like this sed snippet to be portable and thus far it's worked. However, I ran into one box where after I ran the snippet, Subsequent sessions lost the ability to use the letter "e".

The original version I was using looked like this:

Code:
mv /etc/inputrc /tmp/inputrc.orig
sed 's/'\$endif'/\
# alternate mappings for "page up" and "page down" to search the history \
"\e[5~": history-search-backward \
"\e[6~": history-search-forward \
&/' /tmp/inputrc.orig > /etc/inputrc
Then instead of using s/ I thought perhaps i/ would be better so I re-did it as:

Code:
mv /etc/inputrc /tmp/inputrc.orig
sed '/'\$endif'/ {
i\

i\
# alternate mappings for "page up" and "page down" to search the history
i\
"\e[5~": history-search-backward
i\
"\e[6~": history-search-forward
}' /tmp/inputrc.orig > /etc/inputrc
Both of these produce the expected result BUT they both resulted in the loss of the letter "e".

As I mentioned earlier in the post, this was working on 'newer' RHES 5 and up but I have the misfortune of having to support some older RHES 4 boxes in a closed lab. This particular box is an RHES 4u6.

Anyone got any suggestion on how I find out what's happening? Also if some wiser sed heads can give me a more elegant version it would be appreciated.

Thanks in Advance!

Michael E
 
Old 07-27-2011, 11:19 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
How about this:

Code:
echo '# alternate mappings for "page up" and "page down" to search the history
"\e[5~": history-search-backward
"\e[6~": history-search-forward' >> /etc/inputrc
 
1 members found this post helpful.
Old 07-27-2011, 11:57 AM   #3
merana
Member
 
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 80

Original Poster
Rep: Reputation: 15
Wink

Quote:
Originally Posted by MTK358 View Post
How about this:

Code:
echo '# alternate mappings for "page up" and "page down" to search the history
"\e[5~": history-search-backward
"\e[6~": history-search-forward' >> /etc/inputrc
Nice try but then you lose the terminating $endif.

That has to be at the end so it's not just concatenation that has to happen but more of an "insert-between".

Thanks for your suggestion though!
 
Old 07-27-2011, 01:43 PM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi,

the issue that I encountered with your 'sed' was that it swallowed the backslashes. This one worked for me
Code:
sed -i.orig '/$endif/ {i\
\
# alternate mappings for "page up" and "page down" to search the history\
"\\e[5~": history-search-backward\
"\\e[6~": history-search-forward
}' /etc/inputrc
I also removed the redundant '\i'. The above works with
Code:
$ sed --version
GNU sed version 4.2.1
[EDIT]
The -i.orig option will create a backup file before 'sed' makes any changes to the original file. This makes the preceding 'mv' redundant. If something goes wrong then you can restore the original file that has been backupped to /etc/inputrc.orig.

Last edited by crts; 07-27-2011 at 01:46 PM.
 
1 members found this post helpful.
Old 08-02-2011, 11:43 AM   #5
merana
Member
 
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 80

Original Poster
Rep: Reputation: 15
Thanks crts!

That worked perfectly on the hosts I've tried thus far.

The -i.orig is an elegant method rather than my crude mv.

Kudos and Regards,
Michael E
 
  


Reply

Tags
bash, inputrc, sed


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] Strange results from IF statement vomplete Linux - General 2 06-07-2011 10:19 AM
sed and character classes , strange results crispyleif Linux - Newbie 9 02-10-2009 03:08 AM
Strange results when I do a df mlh Linux - General 11 05-31-2007 10:49 AM
APT-GET Results = Strange carlosinfl Debian 2 06-17-2006 02:45 AM
Strange results from dmesg JimBass Linux - Newbie 11 03-27-2005 06:15 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration