Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-05-2006, 01:45 PM   #1
LQ Newbie
Registered: Nov 2004
Distribution: FC6
Posts: 12

Rep: Reputation: 0
command substitution: ^

Take a look at the cmd:

[robert@hydor bin]$ echo hi
[robert@hydor bin]$ ^hi^this is a test
echo this is a test
this is a test
[robert@hydor bin]$

now, my last cmd was "echo this is a test".

So i know how to replace a string in the previous command, what if i want to replace say all the "i"s with any other letter?
...or to replace all the "is" with "hello" or whatever..

..any suggestions?..

Old 04-06-2006, 09:41 AM   #2
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
That would require the use of SED. A tutorial can be found here.

To replace i's with another letter try
 echo "This is a Test" | sed -e 's/i/x/g'
That will replace all the i's with x's.

To replace is with hello try the following:
 echo "This is a Test" | sed -e 's/is/hello/g'
I apologize for the crude explanation. I would give the actual output w/ examples but I'm not on a linux machine currently so I cannot do that. With the code samples and a tutorial you should be good to go. Hope this helps!
Old 04-06-2006, 09:51 AM   #3
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
Here's an example of what I use often, its very powerfull.

debian:~/bin# ls *.sh
debian:~/bin# ls -al !*
ls -al *.sh
-rwxr-xr-x 1 root root 1043 2006-04-04 03:18
-rwxr-xr-x 1 root root  344 2006-02-27 02:35
-rwxr-xr-x 1 root root  466 2006-02-27 02:38
-rwxr-xr-x 1 root root   53 2006-03-04 22:20
debian:~/bin# !ls:gs/sh/ps/
ls -al *.ps
-rw-r--r-- 1 root root 39878 2006-03-31 10:59
Other thing very usefull is Ctrl-R in bash
type something like
press space and you will get your old command, then ctrl R to choose something else

man bash , man!

Last edited by nx5000; 04-06-2006 at 09:53 AM.


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Process Substitution joshholt Programming 4 10-11-2005 03:15 AM
Vim Substitution (specialized) infidel Linux - Software 7 05-07-2005 04:28 PM
sed substitution conditional frostillicus Linux - Newbie 3 04-17-2005 12:36 AM
process substitution jk3us Linux - Software 1 12-02-2004 04:34 PM
Is there any substitution to Ghost? Swift&Smart Linux - Software 12 06-22-2004 05:31 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:08 AM.

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