Sponsored Content
Full Discussion: Create csv from text file
Top Forums Shell Programming and Scripting Create csv from text file Post 302991289 by vgersh99 on Wednesday 8th of February 2017 04:55:09 PM
Old 02-08-2017
Is it something along these lines? Didn't validate all the values...
awk -f jiam.awk input.txt > output.txt
where jiam.awk is:
Code:
BEGIN {
      qq="\""
      FS=qq
      OFS=","

      fldL="ffid,LineNumber,PointNumber,x,y,z,date,Valid,AcquisitionLength,AcquisitionNumber,FileDate,FileSize,GPSTimeOfAcquisition,JulianDay,NumberOfAuxes,NumberOfDeadSeisTraces,NumberOfLiveSeisTraces,NumberOfSeisTraces,RecordLength,SampleRate,SourceEasting,SourceNorthing,SourceLineNumber,SourcePointNumber,SwathName,TapeNumber,SweepLength,TestRecordType,TotalNumberOfTraces,TypeOfSource,PointIndex"

      fldN=split(fldL, fldT, OFS)
      for(i=1; i in fldT; i++)
        fldA[fldT[i]]=i

      print fldL
}
$2 in fldA { printf("%s%s", $(NF-1), (fldA[$2]==fldN)?ORS:OFS)}

---------- Post updated at 04:55 PM ---------- Previous update was at 03:14 PM ----------

here's a little bit more robust version:
Code:
BEGIN {
      qq="\""

      FS=qq
      OFS=","

      fldL="ffid,LineNumber,PointNumber,x,y,z,date,Valid,AcquisitionLength,AcquisitionNumber,FileDate,FileSize,GPSTimeOfAcquisition,JulianDay,NumberOfAuxes,NumberOfDeadSeisTraces,NumberOfLiveSeisTraces,NumberOfSeisTraces,RecordLength,SampleRate,SourceEasting,SourceNorthing,SourceLineNumber,SourcePointNumber,SwathName,TapeNumber,SweepLength,TestRecordType,TotalNumberOfTraces,TypeOfSource,PointIndex,preEasting,preNorthing,postEasting,postNorthing,offset,cogStatus,fleet_nb,VIB1_drive,VIB2_drive,VIB1_vib_status,VIB2_vib_status,VIB1_id,VIB2_id,VIB1_gps_quality,VIB2_gps_quality,VIB1_over_mass,VIB2_over_mass,VIB1_dist_avg,VIB2_dist_avg,VIB1_dist_peak,VIB2_dist_peak"

      fldN=split(fldL, fldT, OFS)
      for(i=1; i in fldT; i++)
        fldA[fldT[i]]=i

      print fldL
}

function arrayFull(a,   i)
{
  for(i=1; i<= fldN; i++)
     if (!(i in a))
        return 0
 return 1
}

arrayFull(outputA) {
  for(i=1; i in outputA; i++)
      printf("%s%s", outputA[i], (i==fldN)?ORS:OFS)
  split("", outputA)
}
$2 in fldA { outputA[fldA[$2]]=$(NF-1) }


Last edited by vgersh99; 02-08-2017 at 05:03 PM..
This User Gave Thanks to vgersh99 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merging files to create CSV file

Hi, I have different files of the same type, as: Time: 100 snr: 88 perf: 10 other: 222 Each of these files are created periodically. What I need to do is to merge all of them into one but having the following form: (2 Replies)
Discussion started by: Ravendark
2 Replies

2. Shell Programming and Scripting

Command to create and update csv file

Hi, I need to create a csv file to store oracle query output. This report need to be created on hourly basis. The csv file report format as "Report_22_Sep_09_13IST.csv". I have the oracle query. Now i need to create and move the oracle query output to the report row by row starting from 3rd row.... (6 Replies)
Discussion started by: Sekar1
6 Replies

3. Shell Programming and Scripting

how to create csv file using shell script

I have a file in multiple directory which has some records in the following format File: a/latest.txt , b/latest.txt, c/latest.txt -> Name=Jhon Age=27 Gender=M Street=LA Road Occupation=Service I want to generate a csv file from the above file as follows File: output.csv -> ... (9 Replies)
Discussion started by: rjk2504
9 Replies

4. Shell Programming and Scripting

How can I create a CSV file from PL/Sql in UNIX?

Can someone help me on creating a script that will manage/create a csv file from Pl/Sql using UNIX?Any advice is welcome,thank you so much,:) (2 Replies)
Discussion started by: Atrap
2 Replies

5. Shell Programming and Scripting

Create an .csv/excel file using shellscript

In my file, i have 4 Product names(For ex:Microsoft excel, Oracle,.Net,IBM websphere,..etc.,) I want this 4 Products in 4 individual .csv/excel file after running the script with those products related information. (12 Replies)
Discussion started by: Navya
12 Replies

6. UNIX for Dummies Questions & Answers

How to create a .csv file from 2 different .txt files?

Hi, I need to create a .csv file from information that i have in two different tab delimited .txt file. I just want to select some of the columns of each .txt file and paste them into a .cvs file. My files look like: File 1 transcript_id Seq. Description Seq. Length ... (2 Replies)
Discussion started by: alisrpp
2 Replies

7. Shell Programming and Scripting

Script to create a CSV file

I created a script that will go out and so a "/sbin/chkconfig --list | egrep XXX" against a server list that would create an output file like the following example: ---------------------------------------------------------------------------------- SERVER1 RC_Script_1 0:off 1:off 2:off... (4 Replies)
Discussion started by: asnatlas
4 Replies

8. Shell Programming and Scripting

Need help. How to create csv file?

Hi I'm a beginner and I have some problem. I have multiple files in the same directory which has one column but rows following the format. File: directory/Disk.txt Content: a b c d e File: directory/Memory.txt a b c d e File: directory/CPU.txt (3 Replies)
Discussion started by: thenuie
3 Replies

9. 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

10. 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
All times are GMT -4. The time now is 08:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy