Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records

Table
---------
Col1 col2 col3 col4 ....................col20 
1     2    3    4   .................... 20
a     b    c    d   .................... v
Output Display
.....................
Col1 col2 col3 col4 ....................col10
1     2    3    4   .................... 10
a     b    c    d .......................j

display Coulmn along with all the record which coulmn 1 to 10 has contained

Col11 col2 col3 col4 ....................col20
11     12   13   14 .....................20
j      k     l    m  .....................v

Not sure I understand your problem. Please improve the spec. Any attempts from your side?

Table
-------

1 2 3 a b c
3 4 5 c d e
7 8 9 f g h

Output Should display
-------

1 2 3 
3 4 5 
7 8 9 
a b c
c d e
f g h

The following shell script works with any amount of whitespace-delimited columns

#!/bin/sh
awk '
NR==1 {x=NF/2}
{
  line=$0
  if (NR==FNR) {
    sub("[[:space:]]+$","",line)
    for (i=NF; i>x; i--) sub("[[:space:]]+[^[:space:]]+$", "", line)
  } else {
    for (i=1; i<=x; i++) sub("[^[:space:]]+[[:space:]]+", "", line)
  }
  print line
}
' "$1" "$1"

The shell script takes the file name as parameter.

Sorry not explain properly
Table

col1 col2 col3 col4 col5 col6    
drwxr-xr-x 4096 Oct 12 07:51 Templates
drwxr-xr-x 4096 Oct 12 07:51 Public
drwxr-xr-x 4096 Oct 12 07:51 Pictures
drwxr-xr-x 4096 Oct 12 07:51 Music
drwxr-xr-x 4096 Oct 12 07:51 Downloads

output should be display col1 and col2 below col1 and col2
col3 col4 col5 col6 should be display.

col1 col2
drwxr-xr-x 4096 
drwxr-xr-x 4096 
drwxr-xr-x 4096 
drwxr-xr-x 4096 
drwxr-xr-x 4096 
col3 col4 col5 col6
Oct 12 07:51 Templates
Oct 12 07:51 Public
Oct 12 07:51 Pictures
Oct 12 07:51 Music
Oct 12 07:51 Downloads

---------- Post updated at 02:36 AM ---------- Previous update was at 02:09 AM ----------

can I add 3 different awk statement make a single awk statement first statement output using the second statement and second statement output using the third awk statement

Every post you have submitted has different requirements for which fields are to be printed on which lines.

There is no pattern I can see that tells us which input fields should be printed on which output lines for an input file that contains N fields. When there were 20 input fields, it appeared that you wanted fields 1-10 printed followed by field 11-20. When there were 6 input fields, first you said you wanted fields 1-3 printed followed by fields 4-6; but now when there are 6 input fields you want fields 1-2 printed followed by fields 3-6.

Please go back to the beginning and explain clearly in English how your script is supposed to determine how many sets of output lines are to be created for the input lines and which input fields are supposed to appear in each set of output lines. Without a clear specification of what you want (other than saying that every suggestion provided is not producing the right output, even though it exactly matches the sample output you said you wanted), we are all wasting our time.

AND, PLEASE use CODE tags when displaying sample input, sample output, and sample code segments.

a little bit verbose, but should be a good starting point - hopefully I understood the reqs.
To get fields 1 and 2: awk -f priti.awk myFile
To get fields 3 and 5: awk -v fld='3 5' -f priti.awk myFile
where priti.awk is:

{
  if (!fld) fld="1 2"
  split(fld, t, FS)
  for(i=1;i in t;i++)
    fldA[t]
}
{
  for(i=1; i<=NF;i++)
   if (i in fldA) printf("%s%s", $i, OFS)
   else
     recA[FNR]=(FNR in recA)?recA[FNR] OFS $i:$i
  printf ORS
  fnr=FNR
}
END {
  for(i=1;i<=fnr; i++)
    if (i in recA)
     print recA
}

My script splits after field x that is calculated as the half of the "number of fields" (NF).

NR==1 {x=NF/2}

You can modify that to a fixed value

NR==1 {x=2}

if we have five fields col1 col2 below col3 then below col4 and col5 will display please help me out using this code code

awk -F "|" '{print $1,$2; s=s $3 ORS ; s=s $3 ; s=s $4 OFS $5 ORS} END{printf "%s%s",s,s}' file

you've been asked to use code tags when posting data/code sample. Please follow the forum rules.

I don't quite understand the requirement - you need to be much more descriptive. Is that something new you need?
What about the previously suggested solutions? Have those been tried? What are the results?

It is getting extremely old producing a new script for each output order you want. Let's try a configurable script. Feed it a configuration file that contains one line for each output section you want to create where each line contains a space separated list of the field numbers you want to print in the section corresponding to the line number in the configuration file and then give it the name of the file you want to extract fields from for the first output section, the name of the file you want to extract fields from for the second output section, etc., with one input file for each line in the configuration file:

#!/bin/ksh
printf '%s\n' "1 2" 3 "6 5 4" | awk '
FNR == 1 {
	fc++
}
fc == 1 {
	# Read fields to be included in each segment of hte output.
	for(i = 1; i <= NF; i++)
		osfo[NR + 1, i] = $i
	osc[NR + 1] = NF
	next
}
{	for(i = 1; i <= osc[fc]; i++)
		printf("%s%s", $osfo[fc, i], i == osc[fc] ? ORS : OFS)
}' - file file file

In this example we create a configuration file (using the printf command in a pipeline and specify the input file name - to read it from standard input) to print fields 1 and 2 in the first output section; field 3 in the second output section; and fields 6, 5, and 4 (in that order) in the third output section. Since the 3 input files in this example all have the same name, we'll be extracting fields from the same file. If the file named file contains:

1 2 3 a b c
3 4 5 c d e
7 8 9 f g h

(as in one of your many examples), the output will be:

1 2
3 4
7 8
3
5
9
c b a
e d c
h g f

If you want to change the output field separators for various sections, you can specify that in the list of files. For example, if you change the last line to:

}' - OFS="," file file OFS="|" file

the output will be:

1,2
3,4
7,8
3
5
9
c|b|a
e|d|c
h|g|f

Will this meet your many and varied requirements?

Yes Thanks for your replay Now I can able to do as per my requirements