Issue with CUT command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with CUT command
# 1  
Old 02-22-2017
Issue with CUT command

Hi All,

I am facing an issue while cutting fields with comma delimiter. There are many records with Double quotes in between.

My data: aaa,bbb,"ccc, ddd",eee,fff,"ggg ,hhh",iii

When i use cut command with comma delimiter, i am getting wrong data like

Code:
field1=aaa 
field2=bbb
field3="ccc
field4= ddd"

But i need data like

Code:
field1=aaa 
field2=bbb
field3="ccc, ddd"

Regards,
Krish

Moderator's Comments:
Mod Comment edit by bakunin: Please use the CODE-tags for code, output and file content, just the way i edited it into your post. Thank you for your consideration.

Last edited by bakunin; 02-22-2017 at 05:42 AM..
# 2  
Old 02-22-2017
How are quotes represented within these double quotes?

Do you need to support new-line characters between the double quotes?

eg:

Code:
aaa,bbb,"""Smokin'"" Joe Frazier","Next
line"

Code:
Field1=aaa
Field2=bbb
Field3="Smokin'" Joe Frazier
Field4=Next
line

# 3  
Old 02-22-2017
Hi,

I do not need new line characters between double quotes.

There are no quotes inside double quotes.

I need field values between double quotes as it is without getting split.

Delimiter is also comma.

Code:
aaa,bbb,"ccc, ddd",eee,fff,"ggg ,hhh",iii

expecting :
Code:
field1=aaa 
field2=bbb
field3="ccc, ddd"
field4=eee



Regards,
Krish

Moderator's Comments:
Mod Comment
Please wrap all code, files, input & output/errors in CODE tags.
It makes it far easier to read and preserves spacing for indenting or fixed width data.

Last edited by rbatte1; 02-22-2017 at 06:53 AM.. Reason: Added CODE tags and corrected spellings
# 4  
Old 02-22-2017
Try this sed script:

Code:
sed 's/\("[^"]*"\)*,\("[^"]*"\)*/\1\n\2/g' infile

For you test record we get:

Code:
aaa
bbb
"ccc, ddd"
eee
fff
"ggg ,hhh"
iii


Last edited by Chubler_XL; 02-22-2017 at 11:36 PM..
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. Shell Programming and Scripting

Cut command issue

Need help to append a pipe at end of the line immediately after the cut command, I have an Input flat file with 16 feilds and I am removing the 16th feild by using the cut command as shown, Input: 354|||||CORPORTATION||||NENE PARADE|||WISBECH|CAMBRIDGESHIRE|PE13 3BY|100001| I... (5 Replies)
Discussion started by: Aditya_001
5 Replies

3. Shell Programming and Scripting

Cut command issue with shell script

I am writing a shell script to skip couple of feilds in a flat file and as a part of this I have written the below piece of code in it. cut -d '|' -f 1-17,19-31 $1 > filename To add pipe at end of the line I used below command, but it adds even to header and footer as well which i... (11 Replies)
Discussion started by: Aditya_001
11 Replies

4. 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

5. Shell Programming and Scripting

Issue with cut and paste

let i have A file and B file A has contains 4 fields as below ---------------- f1 f2 f3 f4 B file consists of 5 fields as below -------------------- f5 f6 f7 f8 f9 need to display as below output: f5 f1 f3 f8 f9 (2 Replies)
Discussion started by: ANSHUMAN1983
2 Replies

6. Shell Programming and Scripting

CUT Command and grep issue

I am trying to grep the oracle erros evry day from the logs file. My problem is : -rw-r----- 1 tibcolm tibco 17438361 Apr 5 11:59 RetryService-RetryService.log -rw-r----- 1 tibcolm tibco 245303 Apr 5 12:00 ResponseService-ResponseService.log -rw-r----- 1 tibcolm tibco 2122654 Apr 5 12:00... (4 Replies)
Discussion started by: neeraj617
4 Replies

7. 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

8. Shell Programming and Scripting

cut command issue from a line of text

Hi, I got a line of text which has spaces in between and it is a long stream of characters. I want to extract the text from certain position. Below is the line and I want to take out 3 characters from 86 to 88 character position. In this line space is also a character. However when using cut... (5 Replies)
Discussion started by: asutoshch
5 Replies

9. Shell Programming and Scripting

Simple Cut issue

I have a long string that looks something like this.... <string>http://abc.com/40/20/zzz061-3472/dP3rXLpPPV2KC846nJ4VXpH7jt4b3LJgkL/tarfile_date.tar</string> I need to but the tar file name. So I need to put between "/" and ".tar</string>". My desired result should be "tarfile_date". (7 Replies)
Discussion started by: elbombillo
7 Replies
Login or Register to Ask a Question