Home > Archive > AWK > January 2005 > compare values
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| akash_g 2005-01-27, 8:55 am |
| hi my name is akash, am a newbie to shell scripts, am facing a situation
that i need help on, any help is greatly appreciated
i have been assigned a task to read two files, contents of each being some
string values each seperated by a comma, then compare the values and create
an error report of all entries that did not match
Eg
a) Contents of File 1
value one,value 2,,value four
b) Contents of File 2
value 1, value 2, value 3, value 4
am required to do a compare of each values, and generate an error report
which describes the error as - "The actual value is "value one" but
generated value is "value 1""
| |
| Ed Morton 2005-01-27, 3:56 pm |
|
akash_g wrote:
> hi my name is akash, am a newbie to shell scripts, am facing a situation
> that i need help on, any help is greatly appreciated
>
> i have been assigned a task to read two files, contents of each being some
> string values each seperated by a comma, then compare the values and create
> an error report of all entries that did not match
>
> Eg
> a) Contents of File 1
> value one,value 2,,value four
> b) Contents of File 2
> value 1, value 2, value 3, value 4
>
> am required to do a compare of each values, and generate an error report
> which describes the error as - "The actual value is "value one" but
> generated value is "value 1""
>
Try this:
awk -F, 'NR==FNR{split($0,act,FS);next}
{ for (i=1;i<=NF;i++)
if ($i != act[i])
printf "The actual value is \"%s\" but generated value
is \"%s\"\n", act[i], $i
}' file1 file2
Regards,
Ed.
| |
| akash_g 2005-01-31, 3:55 am |
| ed, i firstly thank you very much for your time and efforts, i might (am
one) sound like a complete novice but could you please tell me NR, FNR, FS
and NF in your script mean ? thanks for your patience
| |
| akash_g 2005-01-31, 3:55 am |
| ed, i firstly thank you very much for your time and efforts, i might (am
one) sound like a complete novice but could you please tell me NR, FNR, FS
and NF in your script mean ? thanks for your patience
| |
|
| ed, i firstly thank you very much for your time and efforts, i might (am
one) sound like a complete novice but could you please tell me NR, FNR, FS
and NF in your script mean ? thanks for your patience
| |
|
| ed, i firstly thank you very much for your time and efforts, i might (am
one) sound like a complete novice but could you please tell me NR, FNR, FS
and NF in your script mean ? thanks for your patience
| |
| Ed Morton 2005-01-31, 3:56 pm |
|
akash_g wrote:
> ed, i firstly thank you very much for your time and efforts, i might (am
> one) sound like a complete novice but could you please tell me NR, FNR, FS
> and NF in your script mean ? thanks for your patience
>
NR = record number across all input files
FNR = record number within the current input file
FS = field separator
NF = number of fields in the current record.
They're all explained in the awk documentation. See either or both of these:
http://www.gnu.org/software/gawk/manual/gawk.html
http://www.rt.com/man/awk.1.html
Regards,
Ed.
|
|
|
|
|