insert a variable in the last column of a file

i want to insert a variable in the last column of a file, the columns are separated by "|". I want to insert the variable in everyline of the file .

You want to substitute the existing value of the last field,
or you want to append a new filed?

Is is what you are meaning?

$ cat unx.out
fan|2|3.45
fan1|r42|2.15
fanw1|t|5

To insert "jks" in the last column.

$ awk -F "|" '{print $0"|jks"}' unx.out
fan|2|3.45|jks
fan1|r42|2.15|jks
fanw1|t|5|jks

//Jadu

i want to append

cat <filename> | sed s/$/"\|"hello/g > new_file.txt

With awk:

awk '{sub(/[^|]*$/,"&|new value")}1' filename

or

awk 'NF=NF+1{$NF="new value"}1' FS="|" OFS="|"  filename

Use nawk or /usr/xpg4/bin/awk on Solaris.

But i want to use the value of a variable ,when i give $variable its inserting $variable not the value of variable

iam using this snippet-
nawk '{sub(/[^|]*$/,"&|$date")}1' catalog_details.dat

Use this:

nawk '{sub(/[^|]*$/,dt)}1' dt="&|$date" filename