How to print last column of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print last column of line
# 1  
Old 04-14-2010
How to print last column of line

Hello folks,

Please guide me i have a file file.txt that have below text.


PETER JOHN peter@example.com
John Col john@example.com
Sara Paul sara@example.com


I just want to extract only email address list.
# 2  
Old 04-14-2010
try:
Code:
awk '{print $NF}' file

# 3  
Old 04-14-2010
Hammer & Screwdriver with an awk command

Code:
cat myfile | awk '{print $NF}'

or
Code:
awk '{print $NF}' myfile

will output the last field on each line
# 4  
Old 04-14-2010
Thanks so much.

Now i have two files.

files1.txt

Code:
peter
nor
kasi
sssi
appi


files2.txt

Code:
katy
uria
possp
babbbg
seper

first i want to see those contents which are present in file1 but not present in file2, so i see its list, after that i want to see those contents which are present in file2 but not present in file1, i want to see its list as well.

Last edited by vgersh99; 04-14-2010 at 11:01 AM.. Reason: code tags, please!
# 5  
Old 04-14-2010
Oh..Now it seems the question is changed.

Check the manpages of "diff" , "comm".

I hope the command "comm" will suite for your requirement.
# 6  
Old 04-14-2010
.. or grep
Code:
grep -vf file1 file2
grep -vf file2 file1



---------- Post updated at 09:05 AM ---------- Previous update was at 09:03 AM ----------

learnbash you highjack your own thread. If the original problem change you should search the forum first for similar problems/solutions and if you don't find any start a new thread.
Anyway your questions are FAQ !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print whole line with highest value from one column

Hi, I have a little issue right now. I have a file with 4 columns test0000002,10030010330,c_,218 test0000002,10030010330,d_,202 test0000002,10030010330,b_,193 test0000002,10030010020,c_,178 test0000002,10030010020,b_,170 test0000002,10030010330,a_,166 test0000002,10030010020,a_,151... (3 Replies)
Discussion started by: Ebk
3 Replies

2. AIX

Print whole line with highest value from one column

Hi, I have a little issue right now. I have a file with 4 columns test0000002,10030010330,c_,218 test0000002,10030010330,d_,202 test0000002,10030010330,b_,193 test0000002,10030010020,c_,178 test0000002,10030010020,b_,170 test0000002,10030010330,a_,166 test0000002,10030010020,a_,151... (2 Replies)
Discussion started by: Ebk
2 Replies

3. Shell Programming and Scripting

Print next line beside preceding line on column match

Hi, I have some data like below: John 254 Chris 254 Matt 123 Abe 123 Raj 487 Moh 487 How can i print it using awk to have: 254 John,Chris 123 Matt,Abe 487 Raj,Moh Thanks. (4 Replies)
Discussion started by: james2009
4 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. UNIX for Dummies Questions & Answers

Print line with highest value from one column

Hi everyone, This is my first post, but I have already received a lot of help from the forums in the past. Thanks! I've searched the forums and my question is very similar to an earlier post entitled "Printing highest value from one column", which I am apparently not yet allowed to post a... (3 Replies)
Discussion started by: dliving3
3 Replies

6. UNIX for Dummies Questions & Answers

Print line with highest value from one column

Hi everyone, This is my first post, but I have already received a lot of help from the forums in the past. Thanks! I've searched the forums and my question is very similar to an earlier post entitled "Printing highest value from one column", which I am apparently not yet allowed to post a... (1 Reply)
Discussion started by: dliving3
1 Replies

7. Shell Programming and Scripting

read file line by line print column wise

I have a .csv file which is seperated with (;) inputfile --------- ZZZZ;AAAA;BBB;CCCC;DDD;EEE; YYYY;BBBB;CCC;DDDD;EEE;FFF; ... ... reading file line by line till end of file. while reading each line output format should be . i need to print only specific columns let say 5th... (2 Replies)
Discussion started by: rocking77
2 Replies

8. Shell Programming and Scripting

Print entire line based on value in a column

Friends, File1.txt abc|0|xyz 123|129|opq def|0|678 890|pqw|sdf How do I print the entire line where second column has value is 0? Expected Result: abc|0|xyz def|0|678 Thanks, Prashant ---------- Post updated at 02:14 PM ---------- Previous update was at 02:06 PM ---------- ... (1 Reply)
Discussion started by: ppat7046
1 Replies

9. Shell Programming and Scripting

print line before column 1 transitions

I have a space delimited text file with thousands of lines, COLA.TXT that looks for example like this: AA 123 456 789 AA 987 987 987 AA 987 988 888 AA 999 999 999 B 123 456 789 B 111 111 111 CCD 123 456 789 CCD 321 654 987 CCD EE 11 11 EE EE EE 00 00 00 EE Anyway, I need a script... (2 Replies)
Discussion started by: ajp7701
2 Replies

10. UNIX for Advanced & Expert Users

Print the line containing the maximum value in a column

Dear all! I want to find the maximum value in two specific columns with numbers, and then print the entire line containing this value. The file may look like: 1001 34.5 68.7 67 1002 22.0 40.1 32 1003 11.3 34.8 45 I want to find the maximum value within column 2... (22 Replies)
Discussion started by: kingkong
22 Replies
Login or Register to Ask a Question