Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-08-2011
Registered User
 

Join Date: Mar 2011
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
problem with awk script

Hi,
I have two files
Hi,
I have two files

file1 :>


Code:
val="10" port="localhost:8080"httpadd="http:\\192.168.0.239"
file2 :>


Code:
val=${val} val="pdssx" port=${port}port="1324"httpadd=${httpadd}httpadd="raamraav"fileloc=${fileloc}

file3(or file2) should have following output(input from fileone)
file3


file2(or file3)
val="10"val="pdssx" port="localhost:8080"port=="1324"httpadd="http:\\192.168.0.239"httpadd="raamraav"fileloc=${fileloc}
I have tried following code ...
awk -F= 'NR==FNR {_[$1]=$2; next} _[$1] {print $1,_[$1]; next}1' OFS="=" f1 f2
but my code is replcaing as below..

val="10"
val="10"
port="localhost:8080"
port="localhost:8080"
httpadd="http:\\192.168.0.239"
httpadd="http:\\192.168.0.239"
fileloc=${fileloc}

need ur inputs on this...
Sponsored Links
    #2  
Old 04-08-2011
Registered User
 

Join Date: Mar 2011
Posts: 236
Thanks: 1
Thanked 55 Times in 54 Posts
i named your files as t1.txt and t2.txt.
take a look codes below:



Code:
kent$ awk -F'"|=' '{for(i=1;i<=NF;i++)print $i}' t1.txt|sed '/^$/ d' |
awk 'FNR==NR{
    t[FNR]=$0;
        for(i=1;i<=length(t);i+=2){
            gsub(" ","",t[i]);
            a["\\${"t[i]"}"]="\""t[i+1]"\"";
        }
    } NR>FNR{
        for (x in a){
            gsub(x,a[x],$0);
        }
        print $0;
    }' - t2.txt
val="10" val="pdssx" port="localhost:8080"port="1324"httpadd="http:\\192.168.0.239"httpadd="raamraav"fileloc=${fileloc}

Sponsored Links
Closed Thread

Tags
awk compare two files and replace values

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem running a program/script in the background from a script newbie_01 Shell Programming and Scripting 5 03-28-2011 02:14 AM
Problem with script mohitmoudgil Shell Programming and Scripting 6 03-30-2009 04:31 PM
call shell script from perl cgi script problem raksha.s Shell Programming and Scripting 2 03-25-2009 03:50 AM
ssh script problem problem pcjandyala Shell Programming and Scripting 2 07-31-2008 03:27 PM
Problem starting a script from a 'main'-script Rakker UNIX for Dummies Questions & Answers 3 06-28-2005 08:12 AM



All times are GMT -4. The time now is 04:19 AM.