Search Results

Search: Posts Made By: luna_soleil
2,253
Posted By ygemici
#!/bin/bash IFS=$'\n' for i in $(sed ""...
#!/bin/bash
IFS=$'\n'
for i in $(sed "" source)
do
x=$(echo "$i" | sed 's/ .*$//')
y=$(echo "$i" | sed 's/^.* //')
sed -i "/$x/s/.*/<fld n=\"$x\" v=\"$y\" \/\>/" infile.txt
done
...
2,253
Posted By rdcwayx
awk ' NR==FNR{a[$1]=$2;next} {for (i in a) if...
awk '
NR==FNR{a[$1]=$2;next}
{for (i in a) if (match($0,i)) $3="v=\"" a[i] "\""}1
' source.txt datafile
2,253
Posted By pravin27
Try this, awk 'NR==FNR{a[$1]=$2;next} {...
Try this,


awk 'NR==FNR{a[$1]=$2;next} { if ($2 in a) {print $1 FS $2 FS $3 FS a[$2] FS $5} else {print $0}}' source.txt FS="\"" datafile.txt

Or

awk 'NR==FNR{a[$1]=$2;next} {if ($2 in a)...
4,477
Posted By guruprasadpr
Hi The sample file you provided is...
Hi

The sample file you provided is different from your actual file.

Try this:

#awk 'NR==FNR{a[$1]=i++;next}NF>1{print $1,(a[$1])?a[$1]:$2;next}1' FS=, OFS=, i=1 a1 a2 > a2_
#mv -f a2_ a2...
4,477
Posted By guruprasadpr
Hi Make sure the files a1 and a2 are...
Hi

Make sure the files a1 and a2 are brought to their previous states before running the commands. Other than that, I dont see any reason.

Guru
4,477
Posted By guruprasadpr
Hi Not sure why the first one did not work for...
Hi
Not sure why the first one did not work for you.

I will ask you to try the first one again, it should work for you. If not,

#awk 'NR==FNR{a[$1]=i++;next}{print $1,a[$1]}' FS=, OFS=, i=1 a1...
4,477
Posted By guruprasadpr
Hi Just try this: #awk...
Hi

Just try this:
#awk 'NR==FNR{a[$1]=i++;next}{print $1,a[$1]}' FS=, OFS=, i=1 a1 a2
Kitten,1
Dogs,2
Donkey,3
Chicken,4
Turkey,5
Kitten,1
Dogs,2
Donkey,3
Chicken,4
Turkey,5
Kitten,1...
Showing results 1 to 7 of 7

 
All times are GMT -4. The time now is 02:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy