LinuxQuestions.org
Help answer threads with 0 replies.
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 02-04-2008, 01:10 AM   #1
sharath.bv
LQ Newbie
 
Registered: Jan 2008
Posts: 17

Rep: Reputation: 0
" cut command "


Hi all,

I want display only the fist word from each lines of the file.
In each line the words are seperated by TAB's.
----------------------------------
cut -d : -f 1 filename
-----------------------------
 
Old 02-04-2008, 01:17 AM   #2
angrybanana
Member
 
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
Code:
cut -f 1 filename
-d sets the delimiter, in your case you're setting it to ':', it defaults to tab
`man cut` for more info
 
Old 02-04-2008, 01:19 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
cut -f1 filename
TAB is the default delimiter.

Edit: ooops... too late!
 
Old 02-04-2008, 01:32 AM   #4
sharath.bv
LQ Newbie
 
Registered: Jan 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks this command "cut -f 1 filename" works.

But this above command is not working for the below file contents...
----------------------------------------------------
first.xls.ods 1.1 Mon Dec 19 10:52:30 2005 b
test.doc 1.1 Tue Jun 5 10:51:34 2007 b
SourceCode (directory)
TCD (directory)
TM (directory)
design (directory)
prasanth (directory)
tech_docs (directory)
test scripts (directory)

----------------------------------------------------------
Here also i want to display only the first field of each line...

Last edited by sharath.bv; 02-04-2008 at 01:34 AM.
 
Old 02-04-2008, 01:49 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I guess it still depends from the delimiter. If space-delimited this should work
Code:
cut -d\  -f1 filename
please note the double space after backslash: the first is an escaped blank space "\ ". In alternative you can use awk which recognizes either TAB or SPACE as "field separator" so you don't need to specify it every time:
Code:
gawk '{print $1}' filename
 
Old 02-04-2008, 02:38 AM   #6
sharath.bv
LQ Newbie
 
Registered: Jan 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks all i got the answer......
 
  


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
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
C Drive "/dev/hda1" accidently used in dd command at "of=" switch M D Linux - Software 4 04-26-2007 08:56 AM
"list dynamic dependency" of an executable using command other than "ldd" Amrita@3086 Solaris / OpenSolaris 3 04-04-2007 04:56 AM
Tiny Sofa 2.0 - I thought "halt", "reboot" were only root command ?? sorcerer Linux - Distributions 1 08-21-2004 03:28 PM
"segmentation error" when issuing "useradd" command through terminal with RH 9.0 kaihuang Linux - General 0 10-21-2003 11:47 PM

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

All times are GMT -5. The time now is 07:38 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