Alternate command for cut


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alternate command for cut
# 1  
Old 10-20-2006
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  
Old 10-20-2006
you can you this code

Code:
awk -F"," '{print $1","$2","$3}' file_name

as per my concern better to use cut command..
# 3  
Old 10-20-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

2. UNIX for Dummies Questions & Answers

Cut pid from ps using cut command

hay i am trying to get JUST the PID from the ps command. my command line is: ps -ef | grep "mintty" | cut -d' ' -f2 but i get an empty line. i assume that the delimiter is not just one space character, but can't figure out what should i do in order to do that. i know i can use awk or cut... (8 Replies)
Discussion started by: ran ber
8 Replies

3. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

4. Shell Programming and Scripting

alternate for "grep -vf" command

I have been using grep for removing lines of a particular pattern from a long file in the following way grep -vf Exclude_Lines File1 > File2 But grep seems to have some problems because sometimes it does the job, sometimes it does not....I have seen AWK is more powerful.. Can the same thing... (5 Replies)
Discussion started by: ananyob
5 Replies

5. Shell Programming and Scripting

Alternate work out for sed command

Iam trying to insert a line after #Cluster in the property file shown below #Node=Nodehostname:NodeProfilename Node=testNode:test_profile #Cluster=Cluster_Name:nodeName@ClusterMem1,nodeName@ClusterMem2,.... #DC=DCname:DCnodegrp:DCtemp DC=test_DC:test_NG:test_template i was using sed command... (12 Replies)
Discussion started by: SSSB
12 Replies

6. Shell Programming and Scripting

cut command

while read EachRecord do echo "EachRecord = "$EachRecord $EachRecord | cut -f1 #cut -f2 ./input.txt done < input.txt fi * ************* hi guys how can i pass value to cut command from $EachRecord (18 Replies)
Discussion started by: kojo
18 Replies

7. Shell Programming and Scripting

Help with cut command

Gurus, I need help with the cut command : I have a file with garbage charaters at the beginning of each record; but these characters are not of the same length; First record has 3 garbage chars to be removed; rest have 2; If the length was consistent across all the records, I could have... (3 Replies)
Discussion started by: tru_tell
3 Replies

8. UNIX for Dummies Questions & Answers

require alternate command for lsof

Using lsof command i can find out which process-id is associated with the port. lsof -i :51000 . But as part of process i cant have lsof in the server. I am using sun solaris 8 and only kshell. Is there a way to find out which process is using the above port. as of now i am gettn port... (1 Reply)
Discussion started by: logic0
1 Replies

9. Shell Programming and Scripting

cut command

I need to use the cut command with a variable.I have to select a few characters so I tried cut -c30-42 but how do I join it with variable x. Thanks (1 Reply)
Discussion started by: aries
1 Replies
Login or Register to Ask a Question