LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-19-2010, 11:14 AM   #1
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Rep: Reputation: 16
split line...


Hi ...

I have the file below..

kuku, 12 34,AAAA,BB,99
DUDU,43,ggg,hhh,66666
dora,goo, 345 , 677, yyy

How can i outpot only the second column.

Output file: 12 34
43
goo

Thanks.
 
Old 03-19-2010, 11:17 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You can use awk. Let's assume the text is stored in a file called "stuff". Then, you can use

cat stuff | awk -F ',' '{print $2}',

where -F specifies the separator between entries on a line and then we simply print the second column.
 
Old 03-19-2010, 08:05 PM   #3
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
You can also use cut, eg
Code:
cut -d ',' -f 2 <input.txt
(the -d specifies the separator, and the -f specifies the field)

...since there's more than one way to skin a cut
 
Old 03-19-2010, 09:53 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Nylex View Post
You can use awk. Let's assume the text is stored in a file called "stuff". Then, you can use

cat stuff | awk -F ',' '{print $2}',

where -F specifies the separator between entries on a line and then we simply print the second column.
no need cat. its useless.
 
Old 03-20-2010, 01:52 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by ghostdog74 View Post
no need cat. its useless.
Sorry :/. Didn't know that..
 
Old 03-20-2010, 07:59 AM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Nylex View Post
Sorry :/. Didn't know that..
Well, 'cat' in this case was used to convert file into stream, which was redundant. I.e. 'cat' by itself is not useless, but its usage was redundant because 'awk' can get its input from a file.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash] Read file line by line and split on whitespace tskuzzy Programming 4 07-06-2009 03:24 PM
new line matching in PERL in a split function gaynut Programming 2 09-02-2008 12:02 PM
help with c program to read each line from text file, split line , process and output gkoumantaris Programming 12 07-01-2008 12:38 PM
awk messing up trying to split a unicode line by whitespace hedpe Programming 1 08-05-2006 11:10 AM
vim search and replace - split line phreak7t7 Programming 2 08-16-2004 05:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration