Help in cut command

February 9, 2010 at 22:00:46
Specs: Windows XP
Hi Friends, I have a doubt in cut comand..

My file name: test.txt
test1. txt contains the below data:
This is, an example program
My question:
when i use cut command as below
cut -c 1-3,6-7,10-11 test.txt
The result is : Thiisan
But i need result as : Thi is an
each cut values should separate with space.Please help.

Thanks in advance

I


See More: Help in cut command

Report •

#1
February 10, 2010 at 01:49:02
"man cut" reveals the parameter "--output-delimiter"

cut -c 1-3,6-7,10-11 --output-delimiter=" "

cheers

Wollie


Report •

#2
February 10, 2010 at 21:23:48
Wollie, thanks for the reply..i didnt understand your reply and it is not working ..Can you please explain with more detals?

Report •

#3
February 11, 2010 at 04:25:11
just "expand" your statement:

cut -c 1-3,6-7,10-11 --output-delimiter=" " test.txt
(2 leading dashes with output-delimiter, not just 1)


cheers

wollie


Report •

Related Solutions

#4
February 12, 2010 at 18:26:20
Hi Wollie,
I execute the same command but i am not getting the required result..


cut -c 1-3,6-7,10-11 --output-delimiter=" " test.txt
Output is still coming as:
Thiisan

am i missing anything??.. Please suggest


Report •

#5
February 14, 2010 at 16:47:01
The --output delimiter functionality is a GNU extension to the cut command. It's a relatively recent addition. I would say whatever version of cut you are using doens't support this.

This shell script cuts the variable 3 times and glues it back together:

#!/bin/bash

# assuming test.txt has one line
myvar=$(cat test.txt)
v1=$(echo "$myvar"| cut -c 1-3)
v2=$(echo "$myvar"| cut -c 6-7)
v3=$(echo "$myvar"| cut -c 10-11)

echo "${v1} ${v2} ${v3}"


Report •

#6
February 15, 2010 at 19:35:17
Nails, Thank you very much for the detailed reply.

Report •

Ask Question