Get line number in flat file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get line number in flat file
# 1  
Old 03-18-2013
Get line number in flat file

Hi,

Is there a way to find out the line number from where the data starts?
like if the data contains column header, irrespective of the text in the column header we should get the line number from which contains the column header.

I am sorry if I haven't explained the problem clearly.

Thanks
# 2  
Old 03-18-2013
Can you show sample input file?
# 3  
Old 03-18-2013
Quote:
ACCENT_INPUT


Pcode Dealer Name Comp INF
TN16 9BE Ambrose Fisher Ltd Franklin UK Mid Cap Fund A Inc GBP GB00B3ZGH246
TN16 9GF Baggette and Company Wealth Management Limited Templeton Global Bond A Mdis GBP H1 LU0316492692
here the column header is
Quote:
Pcode Dealer Name Comp INF
so I want to get the line number that contains the header, it should be generic

Thanks
# 4  
Old 03-18-2013
Is it always second non-empty line header?
# 5  
Old 03-18-2013
no, its not like that, it keeps changing from file to file, some times the column header comes in the 1st line itself and sometimes in the line 2 or 3 and so on...
# 6  
Old 03-18-2013
Code:
awk '/^Pcode/{print NR;exit}' yourfile

# 7  
Old 03-18-2013
I assumed "ACCENT_INPUT" is your first line in your file. So asked whether second non-empty line "Pcode Dealer Name Comp INF" header.

Is this "ACCENT_INPUT" file name or first line in your file?

If your first non-empty line is header, then try this
Code:
awk ' ! /^$/ { print NR; exit } ' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

2. Shell Programming and Scripting

Replace first number of each line in a file with another number

Hi, I have a set of files in a directory that I have to read and replace the first occurrence of a number with another dummy number. This is what I have so far but it does not seem to work. The files have lot of other data in each row and each data element is separated by ,@, for file in... (13 Replies)
Discussion started by: scorpioraghu
13 Replies

3. UNIX for Dummies Questions & Answers

Inserting a sequential number into a field on a flat file

I have a csv flatfile with a few million rows. I need to replace a field (field number is 85) in the file with a sequential number. As an example, let's assume there are only 4 fields in the file: A,A,,32 A,A,,27 A,B,,43 C,C,,354 If I wanted to amend the 3rd field in this way my... (2 Replies)
Discussion started by: BristolSmithy
2 Replies

4. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

5. Shell Programming and Scripting

Read flat file upto certain number of columns

Hello Guys Please help me with the below issue I want to read a flat file source upto certain number of columns Say my flat file has 30 columns but I want to read upto 25 columns only How come the above issue can be addressed? Thanks a lot!!!! (1 Reply)
Discussion started by: Pratik4891
1 Replies

6. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

7. AIX

How to cut a flat file according to a certain number of characters?

hello everybody i am looking for a shell to cut a flat file (with a long unique line) according to a certain number of characters and redirect every result to an output file. here is an example MyFile : 12 3 456 12 3 456 12 3 456 ..... and i took every 9-characters including BLANKS... (6 Replies)
Discussion started by: fastlane3000
6 Replies

8. UNIX for Dummies Questions & Answers

how to remove the first line from a flat file ?

Hi, I want to remove the first line from a flat file using unix command as simple as possible. Can anybody give me a hand ? Thanks in advance. xli (21 Replies)
Discussion started by: xli
21 Replies

9. Shell Programming and Scripting

how to get the data from line number 1 to line number 100 of a file

Hi Everybody, I am trying to write a script that will get some perticuler data from a file and redirect to a file. My Question is, I have a Very huge file,In that file I have my required data is started from 25th line and it will ends in 100th line. I know the line numbers, I need to get all... (9 Replies)
Discussion started by: Anji
9 Replies

10. Shell Programming and Scripting

how to get rid of blank line in a flat text file

Hi, I have a flat text file which contains blank line between each text line. Is there any command to get rid of it? Thanks for your help (11 Replies)
Discussion started by: xfang
11 Replies
Login or Register to Ask a Question