need to get the last word in comma sep line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to get the last word in comma sep line
# 1  
Old 03-27-2006
need to get the last word in comma sep line

I have a file with
aaa,bbb,ccc,dddd,eee,xyz
aaa,bbb,ccc,dddd,eee,xyz,12345,rty
aaa,bbb,ccc,dddd,eee,xyz,12345,rty,tsrt

1. line columns are not fixed
2. all words are seperated by comma


what i want is always the string after last comma.

regards,
Senthil Kumar Siddhan.
# 2  
Old 03-27-2006
Code:
sed 's/.*,\(.*\)/\1/' myFile

# 3  
Old 03-27-2006
please explain the command

could you please explain the command
# 4  
Old 03-27-2006
Quote:
Originally Posted by vgersh99
Code:
sed 's/.*,\(.*\)/\1/' myFile

.* - 0 or more characters
, - followed by a ','
\(.*\) - followed by 0 or more characters - \(...\) - sed's "capture"
\1 - print the FIRST "capture"

'man sed' for complete details.
# 5  
Old 03-27-2006
Other way..

Code:
awk -F\, '{print $NF}' ${FILE}

# 6  
Old 03-27-2006
i want last word after comma

i want last word after comma
# 7  
Old 03-27-2006
Code:
$ cat kkl  
aaa,bbb,ccc,dddd,eee,xyz
aaa,bbb,ccc,dddd,eee,xyz,12345,rty
aaa,bbb,ccc,dddd,eee,xyz,12345,rty,tsrt
$ awk -F\, '{print $NF}' kkl                                    
xyz
rty
tsrt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bring values in the second column into single line (comma sep) for uniq value in the first column

I want to bring values in the second column into single line for uniq value in the first column. My input jvm01, Web 2.0 Feature Pack Library jvm01, IBM WebSphere JAX-RS jvm01, Custom01 Shared Library jvm02, Web 2.0 Feature Pack Library jvm02, IBM WebSphere JAX-RS jvm03, Web 2.0 Feature... (10 Replies)
Discussion started by: kchinnam
10 Replies

2. Shell Programming and Scripting

Insert single quote on every word separated by comma

Hello, I have a text file as:-ABC BCD CDF DEF EFGI need to convert as 'ABC', 'BCD', 'CDF', 'DEF', 'EFG' using a unix command anybody can help me out on this. Regards, Jas Please wrap all code, files, input & output/errors in CODE tags. It makes them easier to read and preserves... (12 Replies)
Discussion started by: jassi10781
12 Replies

3. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

4. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

5. Shell Programming and Scripting

Script using Sed :Search all patterns & after the last Patter, insert a newLine with Comma Sep Value

I am trying to search the pattern "ARS (11)" and after the LAST pattern, i am trying to open new line and enter text using sed. My Existing Text file is Users.txtpaul, Paul Smith, Stevn Smiley, REQ000001, ARS (11) sam, Sam Martin, Stevn Smiley, REQ000001, ARS (11) mike, Mike Conway, Stevn... (8 Replies)
Discussion started by: evrurs
8 Replies

6. Shell Programming and Scripting

How to grep after the first comma till the next comma in a line

Hi Can any one pls tell me how to grep this line POPULATION,69691,20120509 I want the number 69691 from the above line. How to grep from the first comma till the next comma. Thank You.:confused: (8 Replies)
Discussion started by: rxg
8 Replies

7. Shell Programming and Scripting

Append the text file with comma at the end of every word

Hi folks, Using shell, I am trying the append comma to every line of text. the requirement is like, I have to open the txt file in unix and read line by line and should add comma at the end of every word to make it single line txt file ------- abc@gmail.com bcd@gmail.com... (7 Replies)
Discussion started by: giridhar276
7 Replies

8. Shell Programming and Scripting

Pull Data After Comma if 2 word before comma

Hi, I am trying to truncate word after comma in a file ONLY if there are already 2 words BEFORE comma. If there is one word or 3 or more words BEFORE comma, then I have to leave the data AS IS. See below for example. Input File : John Smith, Manager Smith, John Frank J F K... (2 Replies)
Discussion started by: msalam65
2 Replies

9. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question