LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Easy: Help with Cut command (https://www.linuxquestions.org/questions/programming-9/easy-help-with-cut-command-25839/)

Krash_io 07-15-2002 11:05 PM

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

acid_kewpie 07-16-2002 03:14 AM

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.

Krash_io 07-16-2002 01:10 PM

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.

acid_kewpie 07-17-2002 01:38 AM

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.

Mik 07-17-2002 02:29 AM

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}'


All times are GMT -5. The time now is 07:00 PM.