Finding the last column value from a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding the last column value from a text file
# 1  
Old 06-10-2010
Finding the last column value from a text file

Hi,

I need to find out the last column value from a text file which is delimited by a tab.

The issue here is the last column# for each record can be different i.,e, 1st record can have the last column as 15 and the second record can have the last column as "17".

I have to search a string based on the last column of every record.

Regards
Naveen
# 2  
Old 06-10-2010
read AWK document, and understand the meaning of $NF
# 3  
Old 06-10-2010
This may give you a start

Code:
C:\cygwin\tmp>echo 15,16,9,4,3,22 | gawk -F',' '{print $NF}'
22

C:\cygwin\tmp>echo 15,16,9,4,3,22,49 | gawk -F',' '{print $NF}'
49

To make it easier to see/understand, I used a comma delimiter. You can program for other delimiters like tab, as appropriate.
# 4  
Old 06-10-2010
thanks a lot...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reformatting single column text file starting new line when finding particular string

Hi, I have a single colum file and I need to reformat the file so that it creates a new line every time it come to an IP address and the following lines are corresponding rows until it comes to the next IP address. I want to turn this 172.xx.xx.xx gwpusprdrp02_pv seinwnprd03... (7 Replies)
Discussion started by: kieranfoley
7 Replies

2. UNIX for Dummies Questions & Answers

Replacing a specific column of a text file with another column

Hi, I have a text file in the following format: Code: 13412 NA06985 0 0 2 46.6432798439 4 4 4 4 13412 NA06991 NA06993 NA06985 2 48.8478948517 4 4 2 4 13412 NA06993 0 0 1 45.8022601455 4 4 2 4 13401 NA06994 0 0 1 48.780669145 4 4 4 4 13401 NA07000 0 0 2 47.7312017846 2 4 4 4 ... (2 Replies)
Discussion started by: evelibertine
2 Replies

3. UNIX for Dummies Questions & Answers

Replacing a specific column of a text file with another column

I have a text file in the following format: 13412 NA06985 0 0 2 46.6432798439 4 4 4 4 13412 NA06991 NA06993 NA06985 2 48.8478948517 4 4 2 4 13412 NA06993 0 0 1 45.8022601455 4 4 2 4 13401 NA06994 0 0 1 48.780669145 4 4 4 4 13401 NA07000 0 0 2 47.7312017846 2 4 4 4 13402 NA07019... (3 Replies)
Discussion started by: evelibertine
3 Replies

4. Shell Programming and Scripting

Finding multiple column values and match in a fixed length file

Hi, I have a fixed length file where I need to verify the values of 3 different fields, where each field will have a different value. How can I do that in a single step. (6 Replies)
Discussion started by: naveen_sangam
6 Replies

5. Shell Programming and Scripting

Finding the second last column value from a text file

Can any one tell me how to get the second last column value from the text file, which has different record size for each record. I know how to get the last column using awk and print statements, but I am unable to get the second last column value from the file. (4 Replies)
Discussion started by: naveen_sangam
4 Replies

6. Shell Programming and Scripting

Help with finding text in file

Hello, Please help me with this. I have two files. file1.txt and file2.txt File1 contains text as below txt1 txt2 txt3 txt4 txt5 txt6 txt7 txt8 File2 contains text as below $1 $2 $3 $4 $5 $6 $7 $8 $9 ----------------------------- txt1 txt2 - - - 0 2 8 -*- txt0 txt7 - - - 1 4 8... (3 Replies)
Discussion started by: tenderfoot
3 Replies

7. UNIX for Dummies Questions & Answers

finding text in a file

How do i find text string in a file if i have no idea where the file is? What I am trying to do is find an email address in a file and have no idea where the file is. Thanks (5 Replies)
Discussion started by: §ynic
5 Replies

8. Shell Programming and Scripting

Finding out if there is text in a file.

I have a script that when run creates 4 other text files. Sometimes a couple of these text files are empty. So what I am trying to do is find out if there is text in the file and if not delete the file. What I have so far is the following script. I am just not sure how to return a true value... (9 Replies)
Discussion started by: iCONAN
9 Replies

9. UNIX for Dummies Questions & Answers

finding text inside file

Hi everyone I have a small problem i cant find a soloution to... I'm using digital unix and have to find out all the files which have a certain string inside them and i dont know how to do it. *This search is done as root. *All files from '/' to the last directory should be searched for... (3 Replies)
Discussion started by: dindan100
3 Replies

10. Filesystems, Disks and Memory

finding out the pid for a busy text file

Can some one please tell me how to find out the proccess ID that is holding up a file. I am attempting to remove a file and I am getting a message stating that it is busy. i.e rm filename filename: 777 mode ? (y/n) y rm: filename not removed. Text file busy Thanks in advance. (1 Reply)
Discussion started by: jxh461
1 Replies
Login or Register to Ask a Question