Sponsored Content
Top Forums Shell Programming and Scripting How to delete a columns of a CSV file which has cell values with a string enclosed in " , "? Post 302902067 by Litu19 on Sunday 18th of May 2014 07:17:56 AM
Old 05-18-2014
Hi drl,

Thanks for such a nice brief along with example. I understand that csvtool is an application which takes data as an input and based on the instruction it will process the input data and give the result in as an output.

Let me explain the scenario here what we are looking here.

From an automated application we are getting an input data file in csv format and we need to format that csv file in a specific format as I mentioned above. Here we maynt use any other application like csv tool to format the data (since the file may not be accessible to any other third party application). We are looking for some scripting command to format the input csv file and generate another csv file in side that automated tool which intially generated the input file.

Below is the part of the script which is generating the csv file and creating another csv file from the initial csv file.

Code:
 
// command for generating the initial csv file (file.csv)
blcli_execute Utility exportComplianceRunLatest "${COMPLIANCE_JOB_NAME}""$LOG_LOCATION/$LOG_NAME.csv""CSV"
 
//generating new csv file from initial csv file by removing carriage return. 
 
sed -e ':a' -e 'N' -e '$!ba' -e 's/]]\n/]]/g' file.csv > file1.csv


Currently these 2 commands are used in a shell script which is executing in the automation tool I have explained above. We have observing some problem in second command used to remove the carriage return. Instead of using the second command can you help me to create a new csv file with some specific columns/fields.

I hope you understood my limitation of not using csvtool. We can only use some scriting command to create a new csv file.



---------- Post updated at 04:47 PM ---------- Previous update was at 02:32 PM ----------

In our case we have csv file and data in below format.

Code:
 
file.csv
 
Name,age,permanent_address,current_address,job_location
 
Joel,18,"lanjipalli, ram nagar
1st lane.street4","baner gaon, bitthal
temple Pune", India
 
Litu,24,,"lteligudipalli, hariram nagar
1st lane.street no 8","nuonar gaon, bitthal
temple Pune", India
 
 
expected result(file.csv)
 
name,age,job_location
Joel,18,India
litu,24,India

Note: Here we have space, carriage return and white spaces in permanent and current location.

I think we have issue that we have carriage return in place for 3rd and 4th field in csv file.
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to add two values in the same cell of CSV file

I need help to create a csv file with Unix command. In csv file, i need to put two values in the same cell. Rite now, whts happening is, if i put 2 values in the same cell, its comming as " asd, zxc" but i want it in different line but in same cell. asd zxc Please reply me ASAP. (1 Reply)
Discussion started by: Prashant Jain
1 Replies

2. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

3. UNIX for Dummies Questions & Answers

replace "," with "." only in specific columns of a file?

Hi all, I have this text file containing 9 columns separated by space. The 8th columns contains the numbers. C1 C2 C3 C4 C5 C6 C7 C8 C9 er rt yt gh iu nk il 0.07 xs yt lr ty bg iu zk nh 0,0005 lt ...etc. I want to replace the comma with full stop only in 8th coloumn. the output... (8 Replies)
Discussion started by: Unilearn
8 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

How to delete a column/columns of a CSV file which has cell values with a string enclosed in " , "?

How can I delete a column from a CSV file which has comma separated value with a string enclosed in double quotes and a comma in between? I have a file 44.csv with 4 lines including the header like the below format: column1, column2, column3, column 4, column5, column6 12,455,"string with... (6 Replies)
Discussion started by: dhruuv369
6 Replies

6. Shell Programming and Scripting

Working with CSV files values enclosed with ""

I have a CSV file as shown below "1","SANTHA","KUMAR","SAM,MILLER","DEVELOPER","81,INDIA" "2","KAPIL","DHAMI","ECO SPORT","DEVELOPER","82,INDIA" File is comma delimited.All the field values are enclosed by double quotes. But while using awk or cut, it interprets the comma which is present in... (6 Replies)
Discussion started by: santhansk
6 Replies

7. Shell Programming and Scripting

How to delete the commas in a .CSV file that are enclosed in a string with double quotes?

Okay, I would like to delete all the commas in a .CSV file (TEST.CSV) or at least substitute them with empty space, that are enclosed in double quote. Please see the sample file as below: column 1,column 2,column 3,column 4,column 5,column 6,column 7,column 8,column 9,column 10... (8 Replies)
Discussion started by: dhruuv369
8 Replies

8. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
All times are GMT -4. The time now is 07:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy