Sponsored Content
Full Discussion: CSV from Text file
Top Forums Shell Programming and Scripting CSV from Text file Post 303017631 by jiam912 on Saturday 19th of May 2018 10:49:59 AM
Old 05-19-2018
Don,

It is amazing and much efficient the code i did. Many thanks to improve it. Appreciate your support.

I have other small code that use same input file but select only few columns it is like this;

Code:
awk '/File/{if(s){print s;s=$NF+0}else{s=$NF+0}}
    /Swath Name/{s=s","$NF}
    /Tape #/{s=s","$NF}
    /Tape Label /{s=s","$NF}
    /Line Name/{s=s","$NF}
    /Point Number/{s=s","$NF}
    /Live Seis/{s=s","substr($0,12)}
    /SCI TB Timestamp GPS Time/{s=s","$NF}
    END{print s}' file.txt > 2.csv

Is there any change you check it. For sure you will have a better and efficient idea with this.

here is the output ( 8 selected columns by header )

Code:
5000,1000,2240,X5,40559,38741,40560:38466-39172/2(1-354) 40572:38466-39172/2(355-708) 40584:38466-39172/2(709-1062) 40596:38466-39172/2(1063-1416) 40608:38466-39172/2(1417-1770) 40620:38466-39172/2(1771-2124) 40632:38466-39172/2(2125-2478) 40644:38466-39172/2(2479-2832) 40656:38466-39172/2(2833-3186) 40668:38466-39172/2(3187-3540) 40680:38466-39172/2(3541-3894) 40692:38466-39172/2(3895-4248) 40704:38466-39172/2(4249-4602) 40716:38466-39172/2(4603-4956) 40728:38466-39172/2(4957-5310) 40740:38466-39172/2(5311-5664) 40752:38466-39172/2(5665-6018) 40764:38466-39172/2(6019-6372) 40776:38466-39172/2(6373-6726) 40788:38466-39172/2(6727-7080) 40800:38466-39172/2(7081-7434) 40812:38466-39172/2(7435-7788) 40824:38466-39172/2(7789-8142) 40836:38466-39172/2(8143-8496) 40848:38466-39172/2(8497-8850) 40860:38466-39172/2(8851-9204) 40872:38466-39172/2(9205-9558) 40884:38466-39172/2(9559-9912) 40896:38466-39172/2(9913-10266) 40908:38466-39172/2(10267-10620) 40920:38466-39172/2(10621-10974) 40932:38466-39172/2(10975-11328) 40944:38466-39172/2(11329-11682) 40956:38466-39172/2(11683-12036) 40968:38466-39172/2(12037-12390) 40980:38466-39172/2(12391-12744),1209452095780002
5001,1000,2240,X5,40549,39053,40560:38622-39484/2(1-432) 40572:38622-39484/2(433-864) 40584:38622-39484/2(865-1296) 40596:38622-39484/2(1297-1728) 40608:38622-39484/2(1729-2160) 40620:38622-39484/2(2161-2592) 40632:38622-39484/2(2593-3024) 40644:38622-39484/2(3025-3456) 40656:38622-39484/2(3457-3888) 40668:38622-39484/2(3889-4320) 40680:38622-39484/2(4321-4752) 40692:38622-39484/2(4753-5184) 40704:38622-39484/2(5185-5616) 40716:38622-39484/2(5617-6048) 40728:38622-39484/2(6049-6480) 40740:38622-39484/2(6481-6912) 40752:38622-39484/2(6913-7344) 40764:38622-39484/2(7345-7776) 40776:38622-39484/2(7777-8208) 40788:38622-39484/2(8209-8640) 40800:38622-39484/2(8641-9072) 40812:38622-39484/2(9073-9504) 40824:38622-39484/2(9505-9936) 40836:38622-39484/2(9937-10368) 40848:38622-39484/2(10369-10800) 40860:38622-39484/2(10801-11232) 40872:38622-39484/2(11233-11664) 40884:38622-39484/2(11665-12096) 40896:38622-39484/2(12097-12528) 40908:38622-39484/2(12529-12960) 40920:38622-39484/2(12961-13392) 40932:38622-39484/2(13393-13824) 40944:38622-39484/2(13825-14256) 40956:38622-39484/2(14257-14688) 40968:38622-39484/2(14689-15120) 40980:38622-39484/2(15121-15552),1209492969580002

Appreciate your help.

Last edited by Don Cragun; 05-19-2018 at 02:49 PM.. Reason: Delete duplicated text.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

text file to excel or csv

Hi, I have a text file like ---------------------- aaa|bbb|ccc|ddd|eee fff|gggg|hhhhhh|kkkk -------------------- I have a script which will transfer(thourgh FTP) this text file to windows system. But I want to covert it into excel or CSF then upload into windows system.. thanks (9 Replies)
Discussion started by: srikanthus2002
9 Replies

2. Shell Programming and Scripting

Data fetched from text file and save in a csv file

Hi i have wriiten a script which fetches the data from text file, and saves in the output in a text file itself, but i want that the output should save in different columns. I have the output like: For Channel:response_time__24.txt 1547 data points 0.339 0.299 0.448 0.581 7.380 ... (1 Reply)
Discussion started by: rohitkalia
1 Replies

3. Programming

convert text file to csv

hi all, i have a select query that gives me the output in the following way... SYSTYPE -------------------------------------------------------------------------------- Success Failures Total RFT ---------- ---------- ---------- ---------- TYP 1 0 ... (3 Replies)
Discussion started by: sais
3 Replies

4. Shell Programming and Scripting

Conversion of spaces Text file into CSV format file

Input file (each line is separaed by spaces )given below: Name Domain Contact Phone Email Location ----------------------- ------------------------------------------------ ------- -----... (18 Replies)
Discussion started by: sreenath1037
18 Replies

5. Shell Programming and Scripting

Awk to convert a text file to CSV file with some string manipulation

Hi , I have a simple text file with contents as below: 12345678900 971,76 4234560890 22345678900 5971,72 5234560990 32345678900 71,12 6234560190 the new csv-file should be like: Column1;Column2;Column3;Column4;Column5 123456;78900;971,76;423456;0890... (9 Replies)
Discussion started by: FreddyDaKing
9 Replies

6. Shell Programming and Scripting

Converting data for text file to csv

Gents Using the script attached (raw2csv). i use to create the file .csv.. The input file is called 201.raw. Kindly can you check if there is easy way to do it. The script works fine but takes a lot time to process Thanks for your help (8 Replies)
Discussion started by: jiam912
8 Replies

7. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

8. Shell Programming and Scripting

Process text file to create CSV

I am working on a text file where I have to get data from a text file and convert it into either CSV format or Column format as shown below. OUTPUT Expected GRP Name Pair Size DName DNumber PName PNumber adm_grp Pair1 150.00KG Pair_0ABC_1 0396 Pair_0267_s 1292 ... (6 Replies)
Discussion started by: shunya
6 Replies

9. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

10. Shell Programming and Scripting

Create csv from text file

Gents, I am trying to create a csv file using the file attached. I have a problem to get all information required because the rows are not continues. Here is my code till now. awk ' /"ffid"/{if(s){print s;s=$NF}else{s=$NF}} /"LineNumber"/{s=s $NF} /"PointNumber"/{s=s $NF}... (4 Replies)
Discussion started by: jiam912
4 Replies
Text::WordDiff::HTML(3pm)				User Contributed Perl Documentation				 Text::WordDiff::HTML(3pm)

Name
       Text::WordDiff::HTML - XHTML formatting for Text::WordDiff

Synopsis
	   use Text::WordDiff;

	   my $diff = word_diff 'file1.txt', 'file2.txt'; { STYLE => 'HTML' };
	   my $diff = word_diff $string1,   $string2,    { STYLE => 'HTML' };
	   my $diff = word_diff *FH1,	     *FH2,	   { STYLE => 'HTML' };
	   my $diff = word_diff &reader1,   &reader2,    { STYLE => 'HTML' };
	   my $diff = word_diff @records1,  @records2,   { STYLE => 'HTML' };

	   # May also mix input types:
	   my $diff = word_diff @records1,  'file_B.txt', { STYLE => 'HTML' };

Description
       This class subclasses Text::WordDiff::Base to provide a XHTML formatting for Text::WordDiff. See Term::WordDiff for usage details. This
       class should never be used directly.

       Text::WordDiff::HTML formats word diffs for viewing in a Web browser. The diff content is highlighted as follows:

       o   "<div class="file">"

	   This element contains the entire contents of the diff "file" returned by "word_diff()". All of the following elements are subsumed by
	   this one.

	   o   "<span class="fileheader">"

	       The header section for the files being "diff"ed, usually something like:

		 --- in.txt    Thu Sep	1 12:51:03 2005
		 +++ out.txt   Thu Sep	1 12:52:12 2005

	       This element immediately follows the opening "file" "<div>" element, but will not be present if Text::WordDif cannot deterimine the
	       file names for both files being compared.

	   o   "<span class="hunk">"

	       This element contains a single diff "hunk". Each hunk may contain the following elements:

	       o   "<ins>"

		   Inserted content.

	       o   "<del>"

		   Deleted content.

       You may do whatever you like with these elements and classes; I highly recommend that you style them using CSS. You'll find an example CSS
       file in the eg directory in the Text-WordDiff distribution.

See Also
       Text::WordDiff
       Text::WordDiff::ANSIColor

Support
       This module is stored in an open repository at the following address:

       <https://svn.kineticode.com/Text-WordDiff/trunk/>

       Patches against Text::WordDiff are welcome. Please send bug reports to <bug-text-worddiff@rt.cpan.org>.

Author
       David Wheeler <david@kineticode.com>

Copyright and License
       Copyright (c) 2005-2008 David Wheeler. Some Rights Reserved.

       This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

perl v5.10.0							    2009-09-24						 Text::WordDiff::HTML(3pm)
All times are GMT -4. The time now is 11:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy