The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
alternate lines pstanand Shell Programming and Scripting 6 03-18-2008 11:14 PM
Alternate way for echo. senthil_is Shell Programming and Scripting 5 03-05-2008 09:12 AM
alternate rows of a file dr46014 Shell Programming and Scripting 3 08-25-2007 06:16 AM
Alternate Logon Method? earnstaf Forum Support Area for Unregistered Users & Account Problems 2 08-16-2007 03:54 PM
require alternate command for lsof logic0 UNIX for Dummies Questions & Answers 1 05-17-2007 03:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-20-2006
Mohammed Mohammed is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 12
Alternate command for cut

Hello,

I have a string below

DUMMY=1,2,3,4,5,6

I want to extract fields 1-3 and put it as under in a file
1,2,3

I can do this using cut like below
echo $DUMMY | cut -d, -f1-3

But I would be processing more than 15000 such entries and I found that "cut" was using more CPU. So anyone has any idea an alternate command using awk?

Thanks in Advance
Mohammed
  #2 (permalink)  
Old 10-20-2006
srikanthus2002's Avatar
srikanthus2002 srikanthus2002 is offline
Registered User
  
 

Join Date: Sep 2006
Location: Can u guess...!
Posts: 160
you can you this code

Code:
awk -F"," '{print $1","$2","$3}' file_name
as per my concern better to use cut command..
  #3 (permalink)  
Old 10-20-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
Another ways using KSH :
Code:
echo $DUMMY | IFS=, read f1 f2 f3 filler
echo $f1,$f2,$3
or
Code:
 IFS=, set -A fields -- $DUMMY
echo ${fields[0]},${fields[1]},${fields[2]}
Jean-Pierre
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0