Results 1 to 9 of 9
Hi all,
I got two files say,
file1.txt and
file2.txt
file1.txt content (two fields)
Code:
page=node_1_0_1 category
page=node_1_0_2 brand
file2.txt content (only one field)
Code:
page=node_1_0_1
page=node_1_0_2
Now i want ...
- 12-24-2007 #1
Help on shell script
Hi all,
I got two files say,
file1.txt and
file2.txt
file1.txt content (two fields)
file2.txt content (only one field)Code:page=node_1_0_1 category page=node_1_0_2 brand
Now i want to replace file2.txt with the second field of file1.txtCode:page=node_1_0_1 page=node_1_0_2
I need output like,
How to do this??Any ideas?Code:page=category page=brand
Thanks- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 12-24-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Something like this:
RegardsCode:awk 'FNR==NR{arr[$1]=$1;next} arr[$1]==$1{print}' "file2" "file1"
- 12-24-2007 #3
Hi thanks for ur reply,but i'm not getting expected results.
Code:[oss@pc021698 JAVA]$ awk 'FNR==NR{arr[$1]=$1;next} arr[$1]==$1{print}' "file2.txt" "file1.txt" page=node_1_0_1 category page=node_1_0_2 brand [oss@pc021698 JAVA]$ cat file1.txt page=node_1_0_1 category page=node_1_0_2 brand [oss@pc021698 JAVA]$ cat file2.txt page=node_1_0_1 page=node_1_0_2- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 12-24-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
I think I misread something, to print only lines of file2 if the line exists in file1 try this:
RegardsCode:awk ' FNR==NR{arr[$1]=$1;next} arr[$1]==$1 && $2{split($1,s"=");{print s[1],$2} ' file2 file1
- 12-24-2007 #5
sorry again ,
it shows errors,unexpected new line or end of string
Code:awk: cmd. line:4: arr[$1]==$1 && $2{split($1,s"=");{print s[1],$2} awk: cmd. line:4: ^ unexpected newline or end of string- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 12-24-2007 #6Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
I apologise, a typo, remove the { before the print statement:
RegardsCode:awk ' FNR==NR{arr[$1]=$1;next} arr[$1]==$1 && $2{split($1,s,"=");print s[1],$2} ' file2 file1Last edited by Franklin52; 12-24-2007 at 12:10 PM. Reason: typo
- 12-24-2007 #7
Sorry again ...still not solved....some error in split cmd
Code:awk: cmd. line:3: (FILENAME=file1 FNR=1) fatal: split: second argument is not an array
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 12-24-2007 #8Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Sorry again, I'm just awaked, it must be:
RegardsCode:split($1,s,"=")
- 12-24-2007 #9
it works now


Thanks Franklin .. Thanks for your patience
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------


Reply With Quote