LinuxQuestions.org
Review your favorite Linux distribution.
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


Closed Thread
  Search this Thread
Old 09-16-2013, 03:58 AM   #1
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Rep: Reputation: 1
awk find and replace


hi guys

i have a simple question

i have a directory name like

"P1 ( 13 - 15 ) = 110"

how can i replace 13 and 15 with other variables
e.g i1=3 and i2=5

how can i replace 13 and 15 with $i1 and $i2

i use this code but that does not work

Code:
 
find . -type d -name "P*" |while read FILE
do
echo $FILE | awk '( $3 = "$i1"  ) { $5 = "$i2" } {print} ' 
.
.
.
done

Last edited by mmhs; 09-16-2013 at 04:16 AM.
 
Old 09-16-2013, 04:29 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Can you try:
Code:
~$ echo "P1 ( 13 - 15 ) = 110" | awk '{gsub($3,"$i1",$3) && gsub($5,"$i2",$5); print $0}'
 
Old 09-16-2013, 06:14 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate. Please, follow discussion here: http://www.linuxquestions.org/questi...er-4175477226/
 
  


Closed Thread


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
Question regarding awk or sed to find and replace a word in Solaris for Scripting karthik1asr Linux - Newbie 3 03-29-2013 12:40 PM
AWK find and replace URL blueAlien Linux - General 5 09-29-2010 10:07 PM
awk, sed find and replace recursively from files bluewind Linux - Newbie 17 02-26-2010 11:06 AM
URGENT: Help for Find and Replace with AWK onacorpuscle Linux - Newbie 3 12-07-2007 12:22 PM

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

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