Sponsored Content
Top Forums Shell Programming and Scripting Remove line breaks in csv file using shell script Post 302656011 by rajak.net on Thursday 14th of June 2012 06:41:38 AM
Old 06-14-2012
Remove line breaks in csv file using shell script

Hi All,

I've a csv file in which the record is getting break into 1 line or more than one line. I want to combine those splits into one line and remove the unwanted character existing in the record i.e. double quote symbol ("). The line gets break only when the record contains double quote(") symbol. Please find the following current and expected csv file format.

Current CSV file:
Code:
TESTID1|ACTIVE|Todd|Geller|Marketing Dir-Sales Model (IC)|TIER1
TESTID2|ACTIVE|Todd|Geller|Marketing Dir-Sales Model (MCA)|TIER2
TESTID3|ACTIVE|Todd|Geller|"Marketing Dir-Sales
 Model (MCA)"|TIER4
TESTID3|ACTIVE|Todd|Geller|"Marketing Dir
 
         -Sales
 
 Model (MCA)"|TIER4

Expected CSV file:
Code:
TESTID1|ACTIVE|Todd|Geller|Marketing Dir-Sales Model (IC)|TIER1
TESTID2|ACTIVE|Todd|Geller|Marketing Dir-Sales Model (MCA)|TIER2
TESTID3|ACTIVE|Todd|Geller|Marketing Dir-Sales Model (MCA)|TIER4
TESTID3|ACTIVE|Todd|Geller|Marketing Dir-Sales Model (MCA)|TIER4

I know its bit difficult to find the solution but it would be great if anyone can help me out in getting the script prepared to fix this issue.

Thanks in Advance.

Last edited by Franklin52; 06-14-2012 at 08:05 AM.. Reason: Please use code tags for data and code samples
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

any better way to remove line breaks

Hi, I got some log files which print the whole xml message in separate lines: e.g. 2008-10-01 14:21:44,561 INFO do something 2008-10-01 14:21:44,561 INFO print xml : <?xml version="1.0" encoding="UTF-8"?> <a> <b>my data</b> </a> 2008-10-01 14:21:44,563 INFO do something again I want... (3 Replies)
Discussion started by: csmklee
3 Replies

2. Shell Programming and Scripting

How to append value at first line of CSV file using shell script?

I have an issue where I need to append a value at the last of the csv, I have created a shell script and it is appending the columns at the last but it is appending at all lines, and my requirement is specific to just append at the 1st line. Have a look and suggest, (7 Replies)
Discussion started by: anujrichhariya
7 Replies

3. Shell Programming and Scripting

Piped input to sed 's/\n/ /' doesn't remove the line breaks..

Using ls input as example.. ls | sed 's/\n/ /'outputs with line breaks, where I was expecting the \n to disappear. I've tried \r as well wondering if terminal output used different breaks. Is there a way to remove the line breaks without saving to file and then working from there? ----------... (2 Replies)
Discussion started by: davidpbrown
2 Replies

4. Shell Programming and Scripting

How to remove particular line from file through shell script?

Hi, I am pasring a file line by line. I need to check each field in line and remove particular line. input file lines are, 02;ABC;PQR 03;aaa;rrr 04;ABC;ggg 09;eee;ABC 04;lmn;stu I am looking for line containing "ABC" as field value. Now How can I remove this line from input file... (7 Replies)
Discussion started by: Poonamol
7 Replies

5. Shell Programming and Scripting

shell script to remove extra commas from CSV outp file

Name,,,,,,,,,,,,,,,,,,,,Domain,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Contact,Phone,Email,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Location -----------------------,------------------------------------------------,-------,-----,---------------------------------,------------------------------------ ----... (1 Reply)
Discussion started by: sreenath1037
1 Replies

6. Shell Programming and Scripting

Remove line breaks after a match

I need to remove all line breaks in a document after a match, until there is a blank line. Example below, after the match "THE GREEN TABLE" remove line breaks until a blank line. Then, after the match "THE BLUE TABLE" do the same. Before: THE GREEN TABLE Lorem ipsum dolor sit amet,... (14 Replies)
Discussion started by: dockline
14 Replies

7. Shell Programming and Scripting

Remove Space and blank line from file in UNIX shell script

I have below file. I want to remove space at begining of every line and then after also remove blank line from file. I use below code for each operation. sed -e 's/^*//' < check.txt > check1.txt sed '/^\s*$/d' < check1.txt > check2.txt above code not remove all the space... (12 Replies)
Discussion started by: Mohin Jain
12 Replies

8. Shell Programming and Scripting

Shell script that should remove unnecessary commas between double quotes in CSV file

i have data as below 123,"paul phiri",paul@yahoo.com,"po.box 23, BT","Eco Bank,Blantyre,Malawi" i need an output to be 123,"paul phiri",paul@yahoo.com,"po.box 23 BT","Eco Bank Blantyre Malawi" (5 Replies)
Discussion started by: mathias23
5 Replies

9. UNIX for Beginners Questions & Answers

Remove line breaks and extra spaces

Hi, I want to remove all extra spaces, line breaks . Need a new line entry only for term starting"array" For eg: my input is array(), array(), array(), and my expected output is array(), array(), array(), Is it possible using awk? (5 Replies)
Discussion started by: rsi.245
5 Replies

10. Shell Programming and Scripting

Remove single-line breaks only in document

Regarding copy/pasted text of copyright-free book from archive.org (link below), in attempt to expand single-line-break paragraph text (not section headings or paragraph breaks) to wider right margin, Justify or Wrap in LIbreOffice is not working, and Find/Replace the paragraph mark ($) wraps all... (2 Replies)
Discussion started by: p1ne
2 Replies
RDF::Trine::Model::Union(3pm)				User Contributed Perl Documentation			     RDF::Trine::Model::Union(3pm)

NAME
RDF::Trine::Model::Union - Union models for joining multiple stores together VERSION
This document describes RDF::Trine::Model::Union version 1.000 METHODS
Beyond the methods documented below, this class inherits methods from the RDF::Trine::Model class. "new ( @stores )" Returns a new union-model over the list of supplied rdf stores. "add_statement ( $statement [, $context] )" Adds the specified $statement to the first rdf store. "remove_statement ( $statement [, $context])" Removes the specified $statement from all of the rdf stores. "remove_statements ( $subject, $predicate, $object [, $context])" Removes all statements matching the supplied $statement pattern from all of the rdf stores. "count_statements ($subject, $predicate, $object)" Returns a count of all the statements matching the specified subject, predicate and objects. Any of the arguments may be undef to match any value. "get_statements ($subject, $predicate, $object [, $context] )" Returns a stream object of all statements matching the specified subject, predicate and objects from all of the rdf stores. Any of the arguments may be undef to match any value. BUGS
Please report any bugs or feature requests to through the GitHub web interface at <https://github.com/kasei/perlrdf/issues>. AUTHOR
Gregory Todd Williams "<gwilliams@cpan.org>" COPYRIGHT
Copyright (c) 2006-2012 Gregory Todd Williams. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-29 RDF::Trine::Model::Union(3pm)
All times are GMT -4. The time now is 04:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy