LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-22-2011, 01:50 AM   #1
akhand jyoti
LQ Newbie
 
Registered: Feb 2011
Posts: 12

Rep: Reputation: 1
how to distinguish between tab and space in a file


suppose in tab separated file with n columns and if in a column i put a value which is space separated .how can i able to find out a specific column..ie

NAME<TAB>ADDRESS<TAB>AGE
akhand jyoti<TAB>banglore<TAB>21
vijay<TAB>new delhi<TAB>22
ram kumar verma<TAB>ram nagar<TAB>43
..
..

now i want to print NAME column(or any column).
how can i do that?
thanks in anticipation!
 
Old 03-22-2011, 02:06 AM   #2
retxed
Member
 
Registered: Sep 2009
Location: Chennai
Distribution: Ubuntu 11.10 and back track 4
Posts: 45

Rep: Reputation: 9
I think "cut" command that is a filter in Linux does exactly what you are desiring.....It by default takes TAB as a delimiter.
Look into it....


Quote:
cut -f 1,2 <filename>
will list the names and city.

Hope it helps!!
 
1 members found this post helpful.
Old 03-22-2011, 02:08 AM   #3
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hello,

Have a look at the man page for awk:
Code:
man awk
If you're sure that data are divided by tabs, use \t as field separator and print the desired data.
Code:
awk -F"\t" '{ print $1 }' yourfile
will give you the first column as output. Is that what you're looking for?

Kind regards,

Eric
 
1 members found this post helpful.
Old 03-22-2011, 02:12 AM   #4
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
I think you want the cut command.

Code:
foo$ cut -f 1 < addresses.txt
NAME
akhand jyoti
vijay
ram kumar verma
foo$ cut -f 2 < addresses.txt
ADDRESS
banglore
new delhi
ram nagar
foo$ cut -f 3 < addresses.txt
AGE
21
22
43
foo$
http://www.gnu.org/software/coreutil...cut-invocation

It will work fine as long as your fields are tab delimited and your needs are simple.

If you want to do very complex text transformations then you should look into gawk.

http://www.gnu.org/software/gawk/man...ode/index.html

HTH
 
1 members found this post helpful.
  


Reply

Tags
awk, cut, field, tab


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Distinguish between kernel and user space ramukaka Linux - Kernel 2 08-17-2010 01:14 AM
Distinguish From The A File Contents Which The Processes Are jianelisj Linux - Newbie 1 03-19-2008 01:23 AM
Distinguish from the contents of a file which are the processes (NEWTHREAD) jianelisj Linux - Newbie 1 03-18-2008 02:07 PM
how to distinguish a file and a directory joeyBig Programming 2 10-01-2004 04:21 AM
Tab space in VI (M) ar1 Linux - Software 1 12-07-2003 11:47 PM


All times are GMT -5. The time now is 11:16 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration