1

I have file like Below. But header are in different line the header Values are printed in down to the hear. I want all the header in single row & value to the Particular header to be print to below to the respective header

INPUT

name1    name2           name3            name4
XXXX     IN SERVICE      22905            dhr

Name5
123445678
12345687


Nam6             Name7              Name8   Name9 name10
firstin_firstout godwith             1234   17    david

Name11                                   Name12
dhame                                    Dame2
rame                                     Ragha

OUTPUT

name1   name2   name3   name4   Name5_1 Name5_2 Nam6    Name7   Name8   Name9   name10  Name11_1    Name11_2    Name12_1    Name12_2
XXXX    IN SERVICE  22905   dhr 123445678   12345687    firstin_firstout    godwith 1234    17  david   dhame   rame    Dame2   Ragha
2
  • 1
    A little bit of formatting might help understanding the question better. Commented Nov 5, 2014 at 12:31
  • Please edit this Q, it's unclear what you're asking. Commented Nov 5, 2014 at 12:55

1 Answer 1

0

Save the following by some script.name

#!/usr/bin/awk -f

FNR == 1 {
split ($0,N," ")
r=""
next
}
{
if (FNR>2) r="_" FNR-1
for (i in N) V[N[i] r]=$i
}
FNR == 3 {
for (i in N) {
  V[N[i]"_"1]=V[N[i]]
  delete V[N[i]]
  }
}
END {
for (n in V) printf("%s ", n)
print ""
for (n in V) printf("%s ", V[n])
print ""
}

And operate as follow:

awk -f sript.name input_files | column -t

where the input_file have 1st row with headers and other with data.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.