LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 07-15-2002, 11:05 PM   #1
Krash_io
LQ Newbie
 
Registered: Jul 2002
Location: Bellevue, NE, USA
Posts: 2

Rep: Reputation: 0
Easy: Help with Cut command


I have a datafile that looks like this

----------
asdf fdsa
name eman
email liame
-----------

I want to know how to use the cut command to select the first field in the second row, or the 2nd field in the 2nd row and so on.

Using cut -f2 -d' ' myfile will return the entire second column, I want to be able to select any field from any coulum.

I hope someone can help me out soon! I'm working on a script that I need this for.

Thanks in advance
 
Old 07-16-2002, 03:14 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
this sounds ludicrously like homework. if it is then we are NOT here to do it for you.

either way what ou have found is all that cut will be good for. to get an individual line you'll need to use grep, head, tail or something similar.
 
Old 07-16-2002, 01:10 PM   #3
Krash_io
LQ Newbie
 
Registered: Jul 2002
Location: Bellevue, NE, USA
Posts: 2

Original Poster
Rep: Reputation: 0
How is it that asking about the proper use of the cut command makes you thing it’s a homework assignment? And, I never asked you do my homework, I asked about one single command, I didn’t post the homework assignment up here and ask everyone to write the script for me.

You seem to be on some kind of power trip. After all, this is a Linux forum isn’t it? I mean isn’t the whole point of this site for people to ask questions about Linux? And then people like you who think they walk on water and part waves because they have a “moderator” title come along and totally destroy the whole purpose of a forum because you feel like being a dick.

And, just so you know, this actually is a homework assignment. But, I don’t have to turn it in to anyone; considering I’ve been out of college for sometime now and I’m doing an old assignment for personal gain.
 
Old 07-17-2002, 01:38 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
oh calm the hell down. all i'm saying is that we're not here to do your school work for you, and if it's NOT schoolwork then that's completely different... so many kids get programming assignments and just post them expecting answers, hell they ususally even number them.... no power trip.
 
Old 07-17-2002, 02:29 AM   #5
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
One easy way of getting only the first line would be by using the awk command. Something like this should work:

cat datafile | cut -f 2 -d ' ' | awk '{if (NR==1) print}'
 
  


Reply


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
bash cut command to get df percentage nutthick Programming 8 12-16-2010 11:02 AM
Cut and paste from command line dulli1 Linux - Newbie 9 10-12-2010 09:31 PM
finger and cut command Craig Bowes Linux - Newbie 3 10-09-2004 12:49 PM
Cut Command Help!! fooforon Programming 2 02-05-2004 10:09 AM
cut / awk command?? Sammy2ooo Linux - Newbie 1 05-27-2003 05:46 PM

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

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