Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-28-2012
Registered User
 
Join Date: Oct 2011
Posts: 41
Thanks: 32
Thanked 1 Time in 1 Post
Question on cut

Korn Shell

I have a file whose values are delimited using colon ( : )

Code:
$ cat test.txt
hello:myde:temp:stiker


$ cut -d: -f2,4 test.txt
myde:stiker

I want field 2 and field 4 to be returned but separated by a hyphen. The output should look like

Code:
myde-stiker

How can do this ? (without awk if possible)
Sponsored Links
    #2  
Old 06-28-2012
Registered User
 
Join Date: Mar 2011
Location: Neverland
Posts: 59
Thanks: 12
Thanked 11 Times in 10 Posts
Edit :

Code:
 
$  echo "hello:myde:temp:stiker" | cut -d:   --output-delimiter='-' -f2,4
myde-stiker

Sorry for the first code.
Deleted it
Sponsored Links
    #3  
Old 06-28-2012
Registered User
 
Join Date: Jun 2012
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
@max-hammer

could you describe more about what you mean by this


Code:
--output-delimiter='-' -f2,4

---------- Post updated at 07:01 AM ---------- Previous update was at 07:00 AM ----------
    #4  
Old 06-28-2012
Registered User
 
Join Date: Oct 2011
Posts: 41
Thanks: 32
Thanked 1 Time in 1 Post
It didn't work for me


Code:
# echo "hello:myde:temp:stiker" | cut -d:  --output-delimiter='-' -f2,4
cut: illegal option -- output-delimiter=-
usage: cut -b list [-n] [filename ...]
       cut -c list [filename ...]
       cut -f list [-d delim] [-s] [filename]

#
# echo "hello:myde:temp:stiker" | cut -d:  --output-delimiter="-" -f2,4
cut: illegal option -- output-delimiter=-
usage: cut -b list [-n] [filename ...]
       cut -c list [filename ...]
       cut -f list [-d delim] [-s] [filename]

# cut -d: -f2,4 test.txt --output-delimiter="-"
myde:stiker
cut: cannot open --output-delimiter=-


# cut -d: -f2,4 test.txt --output-delimiter='-'
myde:stiker
cut: cannot open --output-delimiter=-

My environment

Code:
# uname -a
SunOS tigris178 5.10 Generic_147441-01 i86pc i386 i86pc

# echo $0
ksh

Sponsored Links
    #5  
Old 06-28-2012
Registered User
 
Join Date: Mar 2011
Location: Neverland
Posts: 59
Thanks: 12
Thanked 11 Times in 10 Posts
Quote:
--output-delimiter=STRING
use STRING as the output delimiter the default is to use the input delimiter
Its working for me

you can try this


Code:
 
$ echo "hello:myde:temp:stiker" | cut -d:  -f2,4 | tr ':' '-'
myde-stiker

The Following User Says Thank You to max_hammer For This Useful Post:
kraljic (06-28-2012)
Sponsored Links
    #6  
Old 06-28-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,341
Thanks: 144
Thanked 1,754 Times in 1,591 Posts
Or revert to awk:

Code:
awk -F: '{print $2,$4}' OFS=- infile


Last edited by Scrutinizer; 06-28-2012 at 09:01 AM..
Sponsored Links
    #7  
Old 06-28-2012
Registered User
 
Join Date: Oct 2011
Posts: 41
Thanks: 32
Thanked 1 Time in 1 Post
Thank You max_hammer. tr worked for me

Code:
# cut -d: -f2,4 test.txt | tr ':' '-'
myde-stiker

---------- Post updated at 07:32 AM ---------- Previous update was at 07:30 AM ----------

Thank you scrutinizer. awk worked as well

Code:
# cat test.txt | awk -F: '{print $2,$4}' OFS=-
myde-stiker

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
NFS question sam101 Solaris 1 01-27-2011 12:37 PM
sed or awk question thegant UNIX for Dummies Questions & Answers 2 08-15-2008 02:43 PM
OS Question IBravo AIX 1 06-26-2008 06:21 PM
Another Question? PoloRL185 Shell Programming and Scripting 5 05-13-2005 01:10 PM
question hamoudiii UNIX for Dummies Questions & Answers 1 05-02-2005 07:51 PM



All times are GMT -4. The time now is 11:50 PM.