Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > "cut" with linebreak delimiter

"cut" with linebreak delimiter
Thread Tools
wataru
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Jan 7, 2005, 05:59 AM
 
I'm trying to cut the output of something that returns several lines. I only want one of the lines, say the first one. How can I do that with the cut command? Specifically, I can't figure out what the delimiter should be for a new line (\n doesn't work).

Example:
blahblah | cut -d "delimiter" -f 1

I don't have to use cut, either, so if you have another suggestion I'm all ears. FYI, I tried, but I couldn't figure out how to do it in awk.
     
Kristoff
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Jan 7, 2005, 12:18 PM
 
If you just want the first one, use head...


blahblahblah | head -n 1

will give you the first line of what blahblahblah returns.
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
wataru  (op)
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Jan 7, 2005, 12:22 PM
 
Damn, why didn't I think of that!?

I ended up using a different approach that makes the whole thing unnecessary, but thanks!
     
Mithras
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Jan 7, 2005, 01:30 PM
 
Incidentally, I wrote this little script (which I'm sure could be tightened up) to have a quick command for extracting just the line numbers I want:
#!/usr/bin/env perl
use warnings;
use strict;

if ( scalar @ARGV < 2 )
{
print STDERR "Usage: extract.pl start stop [filename]\n";
print " (omit filename to read from STDIN)\n";
exit 127;
}

my $start = shift;
my $stop = shift;

my $count=0;
while (<>)
{
$count++;
if ($count > $stop)
{
exit;
}
if ( $count >= $start )
{
print;
}
}
I save it as printlines so I can just do
complexstuff | printlines 5 10
     
   
 
Forum Links
Forum 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 On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 11:44 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,