awk command help

December 8, 2010 at 07:36:11
Specs: Linux x86_64
I have two files want to copy the last column of the last line of them to two different files in different lines and columns.
let say if the last number of the first two files are 1 and 3 I want to have a new file which contains
1
3
and an other file
1 3

See More: awk command help

Report •

#1
December 8, 2010 at 14:09:16
In awk save the last field and at the END, print out the last field a newfile. Then, use xargs to print the output of the newfile eliminating the carriage returns:

#!/bin/ksh

rm -f newfile otherfile

for ind in file1 file3
do
   awk ' {
      savefield=$NF
   }
   END {
      # print last lines last field
      printf("%s\n", savefield)
   } ' $ind  >> newfile
done

# create the otherfile
xargs < newfile > otherfile


Report •
Related Solutions


Ask Question