UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 20th, 2008, 10:54 AM
corticus corticus is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 2 corticus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 12 sec
Reputation Power: 0
Help with 'cut'

Hi all,

First post, hope I'm in the right place..

I am trying to modify the following line of a shell:
LSTID=`echo $FN | cut -f1 -d' ' | awk -F\. '{print $1}'`
What I want to do is set LSTID to the value contained in the first field of a tab delimited file, $FN.

Thanks!

Reply With Quote
  #2  
Old February 20th, 2008, 11:28 AM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 590 L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 35 m 41 sec
Reputation Power: 100
Send a message via AIM to L7Sqr
$FN is the file name? If that is the case your echo will simply print the name and not the contents of the file.

Code:
$ echo file | cut -f1
file


If you are looking to get at the first column, you will have to process that file.
Code:
$ seq -s'      ' 0 1 10 > file
$ seq -s'      ' 1 1 11 >> file
$ seq -s'      ' 2 1 12 >> file
$ cat file
0       1       2       3       4       5       6       7       8       9      10
1       2       3       4       5       6       7       8       9       10     11
2       3       4       5       6       7       8       9       10      11     12
$ cut -f1 file
0
1
2
$ cut -f1 file | head -n 1
0
__________________
-- I'll provide you with reference points; if they dont work, refer to something else.

If you process text, this might make your life a little easier.

Reply With Quote
  #3  
Old February 20th, 2008, 01:09 PM
corticus corticus is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 2 corticus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 12 sec
Reputation Power: 0
I think I got it,
it is returning the file name (it actually originally returned a set of characters from the name, then I started messing around with it), I see that was the original point of the shell

so I can use seq to grap the first line of the file
and then do cut on that

thanks, I'll go give it a try!

Reply With Quote
  #4  
Old February 20th, 2008, 04:43 PM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 590 L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 35 m 41 sec
Reputation Power: 100
Send a message via AIM to L7Sqr
Quote:
Originally Posted by corticus
so I can use seq to grap the first line of the file

No. the seq was only to fill the file with some tab separated data. (man seq for more details). It's what I did with the file afterwards that you should look at. Sorry for the misdirection there....
Here are the relevant sections:
Code:
$ cut -f1 file
0
1
2
$ cut -f1 file | head -n 1
0

Reply With Quote
  #5  
Old February 21st, 2008, 02:06 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Novice (500 - 999 posts) Click here for more information
 
Join Date: Mar 2006
Posts: 667 SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 22 h 21 m 9 sec
Reputation Power: 196
Just as a passing point, if you just want the first field of first line from file, it is better (more efficient) to do the head first, then the cut.
__________________
"I feel so miserable without you; it's almost like having you here" - Stephen Bishop

Reply With Quote
  #6  
Old February 25th, 2008, 12:58 AM
ghostdog74 ghostdog74 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 95 ghostdog74 User rank is Private First Class (20 - 50 Reputation Level)ghostdog74 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 18 h 34 m 6 sec
Reputation Power: 3
just use awk, no need for cut or head
Code:
LSID=`awk 'NR==1{print $1;exit}' file`

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Help with 'cut'


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway