LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 04-05-2006, 01:45 PM   #1
rhxk
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
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?..

--Rob
 
Old 04-06-2006, 09:41 AM   #2
Centinul
Member
 
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
Code:
 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:
Code:
 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
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

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

Code:
debian:~/bin# ls *.sh
iozone_part.sh  makefullbackup.sh  makeincrementbackup.sh  mmem.sh
debian:~/bin# ls -al !*
ls -al *.sh
-rwxr-xr-x 1 root root 1043 2006-04-04 03:18 iozone_part.sh
-rwxr-xr-x 1 root root  344 2006-02-27 02:35 makefullbackup.sh
-rwxr-xr-x 1 root root  466 2006-02-27 02:38 makeincrementbackup.sh
-rwxr-xr-x 1 root root   53 2006-03-04 22:20 mmem.sh
debian:~/bin# !ls:gs/sh/ps/
ls -al *.ps
-rw-r--r-- 1 root root 39878 2006-03-31 10:59 out.ps
Other thing very usefull is Ctrl-R in bash
type something like
l<ctrl-R>
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.
 
  


Reply


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


All times are GMT -5. The time now is 07:15 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