|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
@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
|
|||
|
|||
|
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
|
|||
|
|||
|
Quote:
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
|
||||
|
||||
|
Or revert to awk: Code:
awk -F: '{print $2,$4}' OFS=- infileLast edited by Scrutinizer; 06-28-2012 at 09:01 AM.. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|