Cut command, no input delim, output delim not working


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cut command, no input delim, output delim not working
# 1  
Old 10-23-2014
Cut command, no input delim, output delim not working

Hello,

I'm using cygwin on my Windows 7 machine.

From the man pages of cut:
--output-delimiter=STRING
use STRING as the output delimiter the default is to use the input delimiter

I tried the following commands and got the error messages:

Code:
$ cut -c1-10,20-30 -d --output-delimiter=| filename
cut: the delimiter must be a single character
Try `cut --help' for more information.
-bash: filename: command not found

$ cut -c1-10,20-30 -d --output-delimiter="|" filename
cut: the delimiter must be a single character
Try `cut --help' for more information.

$ cut -c1-10,20-30 -d --output-delimiter='|' filename
cut: the delimiter must be a single character
Try `cut --help' for more information.

$ cut -c1-10,20-30 -d --output-delimiter'|' filename
cut: the delimiter must be a single character
Try `cut --help' for more information.

$ cut -c1-10,20-30 -d --output-delimiter| filename
cut: the delimiter must be a single character
Try `cut --help' for more information.
-bash: filename: command not found

$ cut -c1-10,20-30 -d --output-delimiter"|" filename
cut: the delimiter must be a single character
Try `cut --help' for more information.

Is it possible that you cannot specify a output delim if you don't specify an input delim? What if there is no input delim in the file...such as a fixed length file and you want an output delim?

Can anyone shed some light on this??? Smilie
Thanks in advance!

Last edited by Corona688; 10-23-2014 at 01:24 PM..
# 2  
Old 10-23-2014
Code:
$ cut -c1-10,20-30 -d --output-delimiter=| filename
cut: the delimiter must be a single character

That error is because of -d or --delimiter
This User Gave Thanks to Aia For This Post:
# 3  
Old 10-23-2014
Please use code tags for code and output, [code]stuff[/code]
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 10-23-2014
With cut -b... and cut -c... the input delimiter is never used anyway. And, since you are creating a single sequence of characters (not fields), I'm not sure you can specify an output field delimiter either. The version of cut I use doesn't have an --output-delimiter option.
You could try:
Code:
cut -c1-10,20-30 --output-delimiter="|" filename

but you'll probably need something more like:
Code:
awk '{print substr($0, 1, 10) "|" substr($0, 20, 11)}' filename

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 10-23-2014
Aia, I tried!

Code:
$ cut -c1-2,4-5 -d --output-delimiter=| t.txt
cut: the delimiter must be a single character
Try `cut --help' for more information.
-bash: t.txt: command not found

Don Cragun, I tried!
$ cut -c1-2,4-5 -d --output-delimiter="|" t.txt
cut: the delimiter must be a single character
Try `cut --help' for more information.

I'm wondering if it is the cygwin environment running on Windows 7!!

Don, the awk command worked nicely!! Much thanks to you both!!
# 6  
Old 10-23-2014
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)



Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 10-23-2014
What is the input delimiter you want, required after '-d'?
Code:
$ cut -c1-2,4-5 -d ' ' --output-delimiter="|" t.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Apply if condition to all lines of tab delim which have same value in a particular column:

Apply if condition (in column 3rd ) to all lines of tab delim which have same value in a particular column (in this case column2) Input: id1 Disease1 High id2 Disease1 Medium id3 Disease1 Low id4 Disease2 Low id5 Disease3 Medium id6 Disease3 Low *** Expected output id1 Disease1 High... (3 Replies)
Discussion started by: Lini
3 Replies

2. Shell Programming and Scripting

Why is my cut command not working ?

OS : RHEL 6.8 Shell : bash I want to remove all lines like below from the history output as it has password. $ history | grep sqlplus 239 sqlplus jn_usr/dxc825#@10.5.12.106/OCSGPD 256 sqlplus osb_soa/KD1egM09@10.5.12.196/BSOAPRD 279 sqlplus jn_usr/dxc825#@10.80.16.219/OCSGPD... (5 Replies)
Discussion started by: John K
5 Replies

3. Shell Programming and Scripting

Cut command not working in for loop

grep -Fxvf testdata.xls file_GTDA1.xls >file_GTDA.xls SLS_COUNT=`grep 'GTDA_Dly_Sls' file_GTDA.xls |wc -l` PMIX_COUNT=`grep 'GTDA_Dly_Pmix' file_GTDA.xls |wc -l` if ; then var1=`cat file_GTDA.xls|grep 'GTDA_Dly_Sls_'` var4="|" for i in $var1... (7 Replies)
Discussion started by: renuk
7 Replies

4. Shell Programming and Scripting

Assinging output of cut command

Hi, I have the files in the following files in a folder 19996587342 19487656550 19534838736 And i need to get the first 6 characters from the abvoe files so i used the following script #!/bin/ksh for i in 19* do txt= `$i | cut -c -6` echo "$txt" done The error is at... (4 Replies)
Discussion started by: smile689
4 Replies

5. UNIX for Dummies Questions & Answers

set output delimiter as tab in cut command

I can not make it work, it prints \t rather than introduce tabs. cut -d "," -f 4,8 Samples.csv --output-delimiter="\t" | sort > out Since I am running this command within a shell script, I tried manually inserting tab in this command, still does not work. I am using bash shell Suggestions... (8 Replies)
Discussion started by: analyst
8 Replies

6. Shell Programming and Scripting

korn shell to cut command output

hello, i use following command: md5sum TEST.xml the output looks like: 900hjidur84hjr938ikv TEST.xml as you can see, the first part is the md5 code, the second part is the file name, but i only want the first part(md5 code), and save it to a file, how to do that? thanks. (2 Replies)
Discussion started by: zbc
2 Replies

7. Shell Programming and Scripting

How to cut selected lines from command output

Hi guys, I need to cut the first 12 system processes from the command ps -A. I know that the cut command forms part of the pipeline but can't understand how to cut the first 12 lines and later display them on standard output. Please help! Many thanks, Jared. (3 Replies)
Discussion started by: jjb1989
3 Replies

8. Shell Programming and Scripting

delim count parsing

Hi all, I have an requirement related to delim count. I want to remove the lines having less than or equal to 2 fields in a csv file. In other words, I want to retrieve the records having more than 2 fields. I can do this using a loop with tr and wc -l command by parsing record by record.... (3 Replies)
Discussion started by: poova
3 Replies

9. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

10. UNIX for Dummies Questions & Answers

How can I cut output of command??

I am on a Linux system using bash shell. I only want to see the number in the Use% field as the output. #df -h / Filesystem Size Used Avail Use% Mounted on /dev/dasda1 2.3G 2.1G 51M 98% / !#/bin/bash df -h / | awk '{print $5}' | cut -c1-2 Us 98 How do... (2 Replies)
Discussion started by: darthur
2 Replies
Login or Register to Ask a Question