Reading column header


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading column header
# 8  
Old 03-14-2013
Hi,

Below are 3 sample files' data
Code:
KAG    IGIN    WPN    WP-Name    KOP-Nmr    KOP-Name  (starts from 1st row)
121    L04760746    9414                                                Growth (EUR) Ant A    93821    AWD-G.f.Wftsb
121    L08522744    7852                                                FdNamens-Ant A.    93826    AWD-G.f.Wftsb



Code:
Nr.    BLZ    VPartner    Status    IAN    WJN    FSname (starts from 3rd row)
                                
1    10700    G&H Ltd    Domain    LU80495    749655     Global Bond 
2    14520    G&H Ltd    Domain    LU60746    941034     Growth Fund



Code:
Pcode    Dealer Name    Comp    INF    Date    Year    
TN16 9BE    Ambrose Fisher Ltd    Franklin UK Mid Cap Fund A Inc GBP    GB00B3ZGH246    5/31/2012    2012  (starts from 2nd row
TN16 9GF    Baggette and Company Wealth Management Limited    Templeton Global Bond A Mdis GBP H1    LU0316492692    5/31/2012    2012

Thanks for helping

Last edited by Franklin52; 03-14-2013 at 04:16 AM.. Reason: Please use code tags for data and code samples
# 9  
Old 03-14-2013
Quote:
Originally Posted by kedar_laveti
Below are 3 sample files' data
From what i see your files have the following structure:

* zero (or several) blank lines
* one header line
* zero (or several) blank lines
* lines of data


The basic method is to cut out all the blank lines first and only then analyse what you have (replace "<b>" and "<t>" with literal blanks/tabs):

Code:
grep -v '^[<b><t>]*$' /path/to/input | /your/script

The grep searches for lines of the form line start followed by optional blanks and/or tabs, followed by line end and outputs every line not fitting this pattern, hence effectively filtering the empty lines.

If your script used awk, sed or any other text filter it might be possible to include this filtering pattern into these scripts to avoid using a separate process for this. This depends on what you actually do to process your files.

I hope this helps.

bakunin
# 10  
Old 03-14-2013
Do you mean this?
Code:
awk 'NF{print; exit}' file

# 11  
Old 03-15-2013
Hi,

Thanks the below code worked

Quote:
nawk 'NF{print; exit}' ASCENTRIC_TRADE_2.txt
But a new file came and it looks like below

Quote:
ACCENT_INPUT
Pcode Dealer Name Comp INF Date Year
TN16 9BE Ambrose Fisher Ltd Franklin UK Mid Cap Fund A Inc GBP GB00B3ZGH246 5/31/2012 2012 (starts from 2nd row
TN16 9GF Baggette and Company Wealth Management Limited Templeton Global Bond A Mdis GBP H1 LU0316492692 5/31/2012 2012
When I tried the code
Quote:
nawk 'NF{print; exit}' ASCENTRIC_TRADE_2.txt
, it prints the first line ACCENT_INPUT, can anyone plz let me know if there is any way to get only the column header depite of the row from which it starts.

Thanks
# 12  
Old 03-15-2013
Code:
awk 'NF && NF>1{print; exit}' ASCENTRIC_TRADE_2.txt


cheers,
Devaraj Takhellambam
# 13  
Old 03-15-2013
Wow!! That worked

Thank you very much Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum of a column as new column based on header in a script

Hello, I am trying to store sum of a column as a new column inside a file but have to find the column names dynamically I/p c1,c2,c3,c4,c5 10,20,30,40,50 20,30,40,50,60 If i want to find sum only column c1, c3 and output it as c6,c7 O/p c1,c2,c3,c4,c5,c6,c7 10,20,30,40,50,30,70... (6 Replies)
Discussion started by: mkathi
6 Replies

2. UNIX for Dummies Questions & Answers

How can i substitute a header column?

Hi, I have a txt file with multiple columns and i want to substitute the header of the first column. Example: Seq. Name Seq. Length #Hits min. eValue mean Similarity #GOs GOs Enzyme Codes InterProScan comp1000201_c0_seq1 ---NA--- 337 0 0 - comp1000297_c0_seq1 ---NA--- 612 0 0 -... (4 Replies)
Discussion started by: alisrpp
4 Replies

3. Shell Programming and Scripting

Add Header to column

hello, can someone helpe me on below issue. i have a list of names and IDs, mick 3424 noah 134 samuel 787 jack 434 i want to add a head for both colum using awk or sed or any tool output NAME ID mick 3424 noah 134 samuel 787 (10 Replies)
Discussion started by: Sara_84
10 Replies

4. Shell Programming and Scripting

Add column header and row header

Hi, I have an input like this 1 2 3 4 2 3 4 5 4 5 6 7 I would like to count the no. of columns and print a header with a prefix "Col". I would also like to count the no. of rows and print as first column with each line number with a prefix "Row" So, my output would be ... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

5. UNIX for Dummies Questions & Answers

Rename a header column by adding another column entry to the header column name

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (1 Reply)
Discussion started by: Vavad
1 Replies

6. Shell Programming and Scripting

Rename a header column by adding another column entry to the header column name URGENT!!

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (4 Replies)
Discussion started by: Vavad
4 Replies

7. Shell Programming and Scripting

Column header

Hello all, We are trying to run a script in Oracle DB from AIX. We need to set the Column Header while executing the query to generate the Output. For eg. select city, name from emp; It need to generate report in .csv format as CITY NAME atla tom cincin jack How I... (1 Reply)
Discussion started by: velappangs
1 Replies

8. Shell Programming and Scripting

getting the column header in the output !

i have a script that access the database and then returns some row. but in the command prompt it it not showing the column header. how to get that ? below the script: ------------------------------------------------------------------------ #!/bin/ksh .... (4 Replies)
Discussion started by: ali560045
4 Replies

9. Shell Programming and Scripting

awk/sed column replace using column header - help

$ cat log.txt Name Age Sex Lcation nfld alias xsd CC 25 M XYZ asx KK Y BB 21 F XAS awe SS N SD 21 M AQW rty SD A How can I replace the column with header "Lcation" with the column with header "alias" and delete the "alias" column? so that the final output will become: Name Age Sex... (10 Replies)
Discussion started by: jkl_jkl
10 Replies

10. Linux

Reading the header of a tar file(posix header)

say i have these many file in a directory named exam. 1)/exam/newfolder/link.txt. 2)/exam/newfolder1/ and i create a tar say exam.tar well the problem is, when i read the tar file i dont find any metadata about the directories,as you cannot create a tar containig empty directories. on the... (2 Replies)
Discussion started by: Tanvirk
2 Replies
Login or Register to Ask a Question