Sponsored Content
Top Forums Shell Programming and Scripting Extract multiple columns base on double quotes as delimiter Post 302951997 by Don Cragun on Wednesday 12th of August 2015 12:16:04 PM
Old 08-12-2015
You can use cut, you just have to keep track of what cut sees as a field separator and what you see as your field separator.

If your fields 2 and 3 ALWAYS contain quoted strings each containing a single comma (as in your sample, you can use cut to get what you want using:
Code:
cut -d, -f1-3,6 file

(realizing that cut sees comma separated fields 2 and 3 are your field 2 and it sees comma separated field 4 and 5 as your field 3).

Or using double-quote as your field separator and realizing that cut would then see the field before the 1st double-quote and the field after the last double-quote as empty, and that cut would see the commas you're viewing as field separators as data between field separators, you could try:
Code:
cut -d'"' -f1-5,8,11 file

where field 1 is the empty field at the start of the line, 2 is your field 1, 3 is the comma separating your fields 1 and 2, 4 is field your field 2, 5 is the comma separating your fields 2 and 3, 8 is your field 4, and 11 is the empty field at the end of your line.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PERL, extract value between double quotes

I know this is probably much simplier than I am making but I need some help please. I have a data file that contains a value on the first line between double quotes ("00043"). I need to assign the value between the first set quotes to a variable in my perl script for comparison analysis. Also,... (6 Replies)
Discussion started by: methos
6 Replies

2. Shell Programming and Scripting

Inserting double quotes after third delimiter

Hi, I'm trying to insert double quotes right after the third delimiter in a file. Delimiter is ^Z. For example: Input: Oct ^Z 1234 ^Z John ^Z Hello!" Desired Output: Oct ^Z 1234 ^Z John ^Z "Hello!" Any ideas? (1 Reply)
Discussion started by: kangaroo
1 Replies

3. Shell Programming and Scripting

To append two columns without double quotes

Hi i have a file with follw data "20090427","0","","16371311","-100200","","","","16371311","JUL","09" In the 10th column i need to convert the month name into month number in this case JUL will be 7 and append the 10th and 11th column which shows me the output as 709. Can you suggest a shell... (11 Replies)
Discussion started by: vee789
11 Replies

4. Shell Programming and Scripting

Multiple double quotes

hi Need to run below command on remote server: cmd -a "1 2" -b 3 If i run below, there's clash matching double quotes and fail. ssh $server "cmd -a "1 2" -b 3" I have few ideas which worked (like keeping the entire cmd in a file and copy it to remote server and then run that file)... (1 Reply)
Discussion started by: reddyr
1 Replies

5. Shell Programming and Scripting

Extract data based on 2nd colume having double quotes

i want extract where the 2nd column having "3" or "7". Based on the forums tried like this but it is not working awk -F"," '$2=3;$2=7 {print}' filename Source "1","2","3","4" "1","3","3","4" "1","7","3","4" "1","8","3","4" "1","2","3","4" "1","2","3","4" Output : ... (5 Replies)
Discussion started by: onesuri
5 Replies

6. Shell Programming and Scripting

Skip the delimiter with in double quotes and count the number of delimiters during data extract

Hi All, I'm stuck-up in finding a way to skip the delimiter which come within double quotes using awk or any other better option. can someone please help me out. Below are the details: Delimited: | Sample data: 742433154|"SYN|THESIS MED CHEM PTY.... (2 Replies)
Discussion started by: BrahmaNaiduA
2 Replies

7. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

8. Shell Programming and Scripting

Replace semicolon within double quotes in a file with semicolon delimiter

Hello Team, Could you please help me with the below question? I have a file with the following properties 1) File Delimiter is ; 2) Text columns are within double quotes 3) Numeric columns will not have double quotes 4) File has total 6 columns Please see a sample record from file ... (3 Replies)
Discussion started by: sam99
3 Replies

9. UNIX for Beginners Questions & Answers

To remove double quotes from specific columns

Hi, I've a requirement like, in a csv file of 30+ fields where all the columns are having double quotes I need to remove the double quotes from certain fields and certain field should remain as it is. Eg:... (6 Replies)
Discussion started by: Krishnanth S
6 Replies

10. Shell Programming and Scripting

Replace double quotes inside the string data for all the columns

Please use code tags Hi, I have input data is below format and n of column in the multiple flat files. the string data has any double quotes(") values replaced to double double quotes for all the columns{""). Also, my input flat file each column string data has carriage of new line too.... (14 Replies)
Discussion started by: SSrini
14 Replies
REMAINDER(3)						   BSD Library Functions Manual 					      REMAINDER(3)

NAME
remainder, remainderf, remainderl, remquo, remquof, remquol -- minimal residue functions LIBRARY
Math Library (libm, -lm) SYNOPSIS
#include <math.h> double remainder(double x, double y); float remainderf(float x, float y); long double remainderl(long double x, long double y); double remquo(double x, double y, int *quo); float remquof(float x, float y, int *quo); long double remquol(long double x, long double y, int *quo); DESCRIPTION
remainder(), remainderf(), remainderl(), remquo(), remquof(), and remquol() return the remainder r := x - n*y where n is the integer nearest the exact value of x/y; moreover if |n - x/y| = 1/2 then n is even. Consequently the remainder is computed exactly and |r| <= |y|/2. But attempting to take the remainder when y is 0 or x is +-infinity is an invalid operation that produces a NaN. The remquo(), remquof(), and remquol() functions also store the last k bits of n in the location pointed to by quo, provided that n exists. The number of bits k is platform-specific, but is guaranteed to be at least 3. SEE ALSO
fmod(3), ieee(3), math(3) STANDARDS
The remainder(), remainderf(), remainderl(), remquo(), remquof(), and remquol() routines conform to ISO/IEC 9899:1999 (``ISO C99''). The remainder is as defined in IEEE Std 754-1985. HISTORY
The remainder() and remainderf() functions appeared in 4.3BSD and FreeBSD 2.0, respectively. The remquo() and remquof() functions were added in FreeBSD 6.0, and remainderl() and remquol() were added in FreeBSD 8.0. BSD
March 30, 2008 BSD
All times are GMT -4. The time now is 03:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy