Sponsored Content
Top Forums Shell Programming and Scripting How to convert 2 column data into multiple columns based on a keyword in a row?? Post 302395440 by ironmask2004 on Tuesday 16th of February 2010 05:35:16 AM
Old 02-16-2010
try next script

Code:
#!/usr/bin/ksh
N=3
count=1
filenames=" "
while [[ $count -lt  $N+1  ]];do
      awk 'BEGIN {RS="SNo"} /No[[:space:]]*'$count'/ {print $0} ' infile > /tmp/tmpf$count
      filenames=$filenames" /tmp/tmpf$count"
   (( count += 1 ))
done

paste $filenames

I edited th post to rewrite the code to replace the paste command with awk command to get best output from the old script:
Code:
#!/usr/bin/ksh
N=3
count=1
filenames=" "
while [[ $count -lt  $N+1  ]];do
      awk 'BEGIN {RS="SNo"} /No[[:space:]]*'$count'/ {print $0} ' infile >  /tmp/tmpf$count
   (( count += 1 ))
done

count=2
while [[ $count -lt  $N+1  ]];do
   awk 'NR==FNR { a[c=FNR]=$0; next } { printf "%-18s\t%-18s\n", a[FNR], $0 } END { for(i=FNR+1;i<=c;i++) print a[i] }' /tmp/tmpf1  /tmp/tmpf$count > /tmp/tfo
   cat /tmp/tfo > /tmp/tmpf1
   (( count += 1 ))
done
cat /tmp/tmpf1



# ./s1
No   1                   No   2                  No  3
I1  Value               I4  Value               I8  Value
I2  Value               I5  Value               I9  Value
I3  Value               I6  Value
                           I7  Value


Last edited by ironmask2004; 02-16-2010 at 07:41 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert two column data into 8 columns

Apologies if this has been covered - I did search but couldn't find what I was looking for. I have a simple X-Y input file. I want to convert it from two columns into 8 columns - 4 pairs of X-Y data. So my input file looks like X1 Y1 X2 Y2 X3 Y3 X4 Y4 X5 Y5 etc And I want it to look... (8 Replies)
Discussion started by: NickC
8 Replies

2. Shell Programming and Scripting

Convert row data to column data

Hi Guys, I have a file as follows: a 1 b 786 c 90709 d 99 a 9875 b 989 c 887 d 111 I want: a 1 9875 b 786 989 (3 Replies)
Discussion started by: npatwardhan
3 Replies

3. Shell Programming and Scripting

sum multiple columns based on column value

i have a file - it will be in sorted order on column 1 abc 0 1 abc 2 3 abc 3 5 def 1 7 def 0 1 -------- i'd like (awk maybe?) to get the results (any ideas)??? abc 5 9 def 1 8 (2 Replies)
Discussion started by: jjoe
2 Replies

4. Shell Programming and Scripting

Splitting data from one row as multiple columns

Hi I have a file containing some data as follows: 11-17-2010:13:26 64 4 516414 1392258 11-17-2010:13:26 128 4 586868 695603 11-17-2010:13:26 256 4 474937 1642294 11-17-2010:13:32 64 4 378715 1357066 11-17-2010:13:32 128 4 597981 1684006 ... (17 Replies)
Discussion started by: annazpereira
17 Replies

5. UNIX for Advanced & Expert Users

Convert column data to row data using shell script

Hi, I want to convert a 3-column data to 3-row data using shell script. Any suggestion in this regard is highly appreciated. Thanks. (4 Replies)
Discussion started by: sktkpl
4 Replies

6. Shell Programming and Scripting

Convert row to columns start from nth column

Dear All, We have input like this: 161 57 1378 176 1392 262 1444 441 1548 538 1611 670 1684 241 57 1378 208 1393 269 1447 444 1549 538 1610 677 1700 321 ... (4 Replies)
Discussion started by: attila
4 Replies

7. Shell Programming and Scripting

Convert Data from Column to Row

Hi FileA.txt E_TIM 16, ETE 15, EOND 26, EEC 81, E_1 un, E_2 un, E_3 un, E_4 284, E_TIM 17, ETE 15, EOND 29, EEC 82, E_1 un, E_2 un, E_3 un, E_4 249, (6 Replies)
Discussion started by: asavaliya
6 Replies

8. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

9. Shell Programming and Scripting

Paste columns based on common column: multiple files

Hi all, I've multiple files. In this case 5. Space separated columns. Each file has 12 columns. Each file has 300-400K lines. I want to get the output such that if a value in column 2 is present in all the files then get all the columns of that value and print it side by side. Desired output... (15 Replies)
Discussion started by: genome
15 Replies

10. Shell Programming and Scripting

Join columns across multiple lines in a Text based on common column using BASH

Hello, I have a file with 2 columns ( tableName , ColumnName) delimited by a Pipe like below . File is sorted by ColumnName. Table1|Column1 Table2|Column1 Table5|Column1 Table3|Column2 Table2|Column2 Table4|Column3 Table2|Column3 Table2|Column4 Table5|Column4 Table2|Column5 From... (6 Replies)
Discussion started by: nv186000
6 Replies
srf_list(1)							   Staden io_lib						       srf_list(1)

NAME
srf_list - Lists and/or counts the contents of an SRF file SYNOPSIS
srf_list [options] srf_archive ... DESCRIPTION
srf_list lists the filenames held within one or more SRF container. To simply count the contents rather than list them specify the -c option. Note that when in count-only mode if an index is present it will be used to determine the number of entries in the index and hence sequences in the SRF file. The index cannot be used when listing the filenames however as the index itself does not contain the full file- names. Note that it is not possible to count sequences matching certain patterns or with specific flags set. srf_info is a more general purpose tool that may cover this. OPTIONS
-c Counts sequences instead of listing them. Note that this may be substantially faster than listing if an index exists. -v Verbose mode. This gives summary count information per file rather than just the total at the end. -l Long format. When listing sequence names this also provides information on the position in the archive and the size of the sequence specific data block and the size of the shared data block header. EXAMPLES
To count the total number of sequences in several SRF files: srf_list -c *.srf To produce a "fofn" (file of filenames) for an SRF file: srf_list foo.srf > foo.fofn AUTHOR
James Bonfield, Wellcome Trust Sanger Institute September 29 srf_list(1)
All times are GMT -4. The time now is 03:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy