Sponsored Content
Top Forums Shell Programming and Scripting Column with New Line in CSV file Post 302916318 by Yoda on Monday 8th of September 2014 05:23:24 PM
Old 09-08-2014
Code:
awk -F, '
        # if NF not equal to 7
        NF != 7 {
                # If ORS not equal to " " set ORS = " " else set ORS = RS (newline by default)
                ORS = ( ORS != " " ? " " : RS )
        }
        {
                # This stmt rebuilds current record, this is to set OFS = |
                $1 = $1
        }
        # 1 == true. If true, default awk operation is to print current record
        1
' OFS=\| file

This User Gave Thanks to Yoda For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

read a line from a csv file and convert a column to all caps

Hello experts, I am trying to read a line from a csv file that contains '.doc' and print the second column in all caps. e.g. My csv file contains: Test.doc|This is a Test|test1|tes,t2|test-3 Test2.pdf|This is a Second Test| test1|tes,t2|t-est3 while read line do echo "$line" |... (3 Replies)
Discussion started by: orahi001
3 Replies

2. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, My requirement is to remove line (3 Replies)
Discussion started by: r_t_1601
3 Replies

3. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, i have a csv file . In the 7th column i have data that has line feed in it. Requirement is to remove the line feed from the 7th column whenever it appears There are 11 columns in the file C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11 The value in C7 contains line feed ( Alt + Enter ),... (2 Replies)
Discussion started by: r_t_1601
2 Replies

4. Shell Programming and Scripting

Replace 2nd column of CSV file with numbers on line

I have a csv file with occasional multiple entries in the second column. 111111,104,07-24-2011,3.15,N, 222222,020 140,07-24-2011,10.00,N,I want the result 111111,104,07-24-2011,3.15,N, 222222,020,07-24-2011,10.00,N, 222222,140,07-24-2011,10.00,N, I know I can get the output of the second... (5 Replies)
Discussion started by: ffdstanley
5 Replies

5. Shell Programming and Scripting

Replace 2nd column for each line in a csv file with fixed string+random number

Hi experts, My csv file looks like this U;cake;michael;temp;;;; U;bread;john;temp;;;; U;cocktails;sarah;temp;;;; I'd like to change the value fo 2nd column to cf+random number , which will look maybe something like this U;cf20187;michael;temp;;;; U;cf8926;john;temp;;;;... (7 Replies)
Discussion started by: tententen
7 Replies

6. Shell Programming and Scripting

Extract Line and Column from CSV Line in ksh or bash format

Hi, I was doing some research and can't seem to find anything. I'm trying to automate a process by creating a script to read a csv line and column and assigning that value to a variable for the script to process it. Also if you could tell me the line and column if it's on another work ... (3 Replies)
Discussion started by: vpundit
3 Replies

7. Shell Programming and Scripting

Remove the values from a certain column without deleting the Column name in a .CSV file

(14 Replies)
Discussion started by: dhruuv369
14 Replies

8. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

9. Shell Programming and Scripting

Get maximum per column from CSV file, based on date column

Hello everyone, I am using ksh on Solaris 10 and I'm gathering data in a CSV file that looks like this: 20170628-23:25:01,1,0,0,1,1,1,1,55,55,1 20170628-23:30:01,1,0,0,1,1,1,1,56,56,1 20170628-23:35:00,1,0,0,1,1,2,1,57,57,2 20170628-23:40:00,1,0,0,1,1,1,1,58,58,2... (6 Replies)
Discussion started by: ejianu
6 Replies
Perl6::Say(3pm) 					User Contributed Perl Documentation					   Perl6::Say(3pm)

NAME
Perl6::Say - "print" -- but no newline needed SYNOPSIS
# Perl 5 code... use Perl6::Say; say 'boo'; # same as: print 'boo', " " say STDERR 'boo'; # same as: print STDERR 'boo', " " STDERR->say('boo'); # same as: print STDERR 'boo', " $fh->say('boo'); # same as: print $fh 'boo', " "; say(); # same as: print "$_ "; say undef; # same as: print " "; DESCRIPTION
Note for Users of Perl 5.10 You don't need this module. The Perl 6 "say" function is available in Perl 5.10 by saying "use feature 'say';". Hence, this module is of interest only to users of Perl 5.6 and 5.8. If you have Perl 5.10 installed, see the 510/ directory in this distribution for some elementary examples of "say" taken from "perldoc fea- ture". General Implements a close simulation of the "say" function in Perl 6, which acts like "print" but automatically appends a newline. Use it just like "print" (except that it only supports the indirect object syntax when the stream is a bareword). That is, assuming the relevant filehandles are open for output, you can use any of these: say @data; say FH @data; FH->say(@data); *FH->say(@data); (*FH)->say(@data); say $fh, @data; $fh->say(@data); but not any of these: say {FH} @data; say {*FH} @data; say {*FH} @data; say $fh @data; say {$fh} @data; Additional Permitted Usages As demonstrated in the test suite accompanying this distribution, "Perl6::Say::say()" can be used in all the following situations. $string = q{}; open FH, ">", $string; say FH qq{Hello World}; # print to a string close FH; # requires Perl 5.8.0 or later use FileHandle; $fh = FileHandle->new($file, 'w'); if (defined $fh) { say $fh, qq{Hello World}; $fh->close; } use IO::File; $fh = IO::File->new($file, 'w'); if (defined $fh) { say $fh, qq{Hello World}; $fh->close; } $string = q{}; open FH, ">", $string; # requires Perl 5.8.0 or later select(FH); say qq{Hello World}; close FH; Interaction with Output Record Separator In Perl 6, "say @stuff" is exactly equivalent to "Core::print @stuff, " "". That means that a call to "say" appends any output record separator (ORS) after the added newline (though in Perl 6, the ORS is an attribute of the filehandle being used, rather than a global $/ variable). "IO::Handle::say()" IO::Handle version 1.27 or later (which, confusingly, is found in IO distribution 1.23 and later) also implements a "say" method. Perl6::Say provides its own "say" method to IO::Handle if "IO::Handle::say" is not available. Usage with Older Perls As noted above, some aspects of "Perl6::Say::say()" will not work with versions of Perl earlier than 5.8.0. This is not due to any problem with this module; it is simply that Perl did not support printing to an in-memory file ("print $string, " ";") prior to that point. (Thanks to a CPAN testers report from David Cantrell for identifying this limitation.) WARNING
The syntax and semantics of Perl 6 is still being finalized and consequently is at any time subject to change. That means the same caveat applies to this module. DEPENDENCIES
No dependencies other than on modules included with the Perl core as of version 5.8.0. Some of the files in the test suite accompanying this distribution use non-core CPAN module IO::Capture::Stdout. Tests calling IO::Cap- ture::Stdout methods are enclosed in "SKIP" blocks and so should pose no obstacle to installation of the distribution on systems lacking IO::Capture. (However, the maintainer strongly recommends IO::Capture for developers who write a lot of test code. So please consider installing it!) AUTHOR and MAINTAINER AUTHOR Damian Conway (damian@conway.org). MAINTAINER James E Keenan (jkeenan@cpan.org) (effective v0.06, July 2006). ACKNOWLEDGMENTS
Thanks to Damian Conway for dreaming this up. Thanks to David A Golden for a close review of the documentation. Thanks to CPAN tester Jost Krieger for reporting an error in my SKIP block count in one test file. BUGS AND IRRITATIONS
As far as we can determine, Perl 5 doesn't allow us to create a subroutine that truly acts like "print". That is, one that can simultane- ously be used like so: say @data; and like so: say {$fh} @data; Comments, suggestions, and patches welcome. COPYRIGHT
Copyright (c) 2004, Damian Conway. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. perl v5.8.8 2008-02-09 Perl6::Say(3pm)
All times are GMT -4. The time now is 10:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy