Shell script for .Txt to .csv conversion with data processing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script for .Txt to .csv conversion with data processing
# 8  
Old 01-04-2015
Having read and appreciating the comments, and being as overwhelmed as the others by the data files, and having removed the <CR> line terminators from the DOS/windows files, I'd like to propose for discussion (hoping to have guessed the requirements correctly)
Code:
awk     'FNR==NR        {T[$1]=$2; next}
         FNR==1         {$0=toupper($0) 
                         for (n=1; n<=100; n++) if ($n in T) C[$n]=n
                         getline
                         next   
                        }
                        {for (n in T) if (C[n]) print FNR, n, T[n], $4, $(C[n])
                        }
        ' OFS="," /tmp/paramaters.txt /tmp/CNAI_DUMP_RAW1.txt

This is working on a subset of the data; applying it to the entire data set as well as redirecting it to the desired output file is left to the reader.
# 9  
Old 01-04-2015
Gautam Banerjee,

Some of the space separated key/value pairs of parameters.txt are malformed:
Code:
NCCPERM As Per BSIC PLAN
CS 1 for non MBC
CHAP 6 for MBC
CHAP 11 for BCCH on OL

Also, providing five lines of 4068 columns each is not a good example of an input datafile. Can you provide the columns that are pertinent to the problem at hand?

As Don Cragen as requested, please give better description of what you are trying to accomplish, including output? This should include something like:
For example, on line 4 of the input sample data, the value of the 5 column ("a.dent") is used as the lookup key in the parameters table. The returned value ("towel") is used as column 4 of the output file.

The result should look something like:
Code:
$1 $2 $4 lookup($5)

This User Gave Thanks to derekludwig For This Post:
# 10  
Old 01-04-2015
Also for discussion, here's how CNAI_DUMP_RAW1.txt appears when loaded into Gnumeric. Each line extends to column EZL. I don't suppose it matters how many columns that is?
Shell script for .Txt to .csv conversion with data processing-screenshot-cnai_dump_raw1txt-gnumericpng
Shell script for .Txt to .csv conversion with data processing-screenshot-cnai_dump_raw1txt-gnumericpng
This User Gave Thanks to ongoto For This Post:
# 11  
Old 01-04-2015
Hi experts,

I have pasted a small sample of two inputs and one output desired.

Any suggestions on how to get the desired output using awk, sed or a shell script file?
Image

Please suggest some code to achieve the desired output.csv
# 12  
Old 01-04-2015
Code:
Parameter   Ideal Value     Cell Name       Actual Value
---------   -----------     ---------       ------------
accmin      Ranges          RBR201A         100
cchpwr      33              RBR201A         33
cchpwr      30              RBR201A         33
att         yes             RBR201A         yes
...
...
maxret      2               RBR201A         1

@ Gautam Banerjee
Is this sample output close to the output you are looking for?
This User Gave Thanks to ongoto For This Post:
# 13  
Old 01-04-2015
Gautam Banarjee,

Can you check the parameters.txt file that your provided? There are differences between your OnGoto's postings. For example, the parameter accmin has a value of '100' as shown by your posting, while the file has 'RANGES', as shown by OnGoto.

Please also remember that standard CSV does not provide a method to highlight values or cells.

- DL
This User Gave Thanks to derekludwig For This Post:
# 14  
Old 01-04-2015
Please help us help you.

I applaud your efforts to show us reasonable sized sample inputs and corresonding output. But, PLEASE, don't show us pictures of data. (Especially with some data truncated due to field widths in the pictures of tables you show us.) Give us text (in CODE tags) that we can copy and paste into files we can use as test data to try to test code we might write to solve your problem!

I see that the name of one of your input files has changed from paramaters.txt to parameters.txt (and that is good), but why does parameters.txt show four data rows while your expected output has six data columns? Why is the 3rd column in your output (with heading limit1) present when limit1 does not appear in parameters.txt?

You don't show what field separators are to be used in your output. Although most .csv files use comma as the separator, that isn't always the case.

And, flat text .csv files don't contain red coloring. Explain how (or if) this distinctive output is supposed to actually appear in output.csv.

And, please be sure that the sample data you provide is representative of problems your script will have to handle. For example, your original data files contained things like:
Code:
NCCPERM As Per BSIC PLAN
CHAP 6 for MBC
CHAP 11 for BCCH on OL

which I assume in your latest example should now be:
Code:
nccperm As Per BSIC PLAN
chap 6 for MBC
chap 11 for BCCH on OL

but your latest sample doesn't show us anything like these cases.

Please explain what the output should look like for a column with the header nccperm? Should it be nccperm(As) or nccperm(As Per BSIC PLAN) or nccperm(as) or nccperm(as per basic plan) or something else?

Which input line is supposed to be used for chap? Or are there supposed to be two copies of that input column in the output.csv file with different values in parentheses on the header line?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

2. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

3. Shell Programming and Scripting

Copy data to CSV file from txt output

Hi Everyone , Below is output from a TL1 , I want just the NE Name: and beside that the Temperature and the voltages in a csv file , Is this possible? > act-user:AB1S2a:ArshadFO:493::**********; AB1S2a 2016-02-07 10:13:24 M 493 COMPLD "ArshadFO:2016-02-07 10-04-55,0" ;... (11 Replies)
Discussion started by: adgjmpt
11 Replies

4. Shell Programming and Scripting

Conversion of xhtml data into csv format using dump utility

Hi Unix Gurus, I tried to convert the attached xhtml table content into csv file using unix shell script (lynx -dump filename) and got the below results: Title ID Owner Priority Estimate Project Change Date Changed By Complexity Create Date Created By Detail Estimate Total De tail... (6 Replies)
Discussion started by: bi.infa
6 Replies

5. Shell Programming and Scripting

Conversion of below Tabs Tex file into CSV format file : shell script needed

Request if some one could provide me shell script that converts the below "input file" to "CSV format file" given Name Domain Contact Phone Email Location ----------------------- ------------------------------------------------ ------- ----- ---------------------------------... (7 Replies)
Discussion started by: sreenath1037
7 Replies

6. Shell Programming and Scripting

Shell script for CSV conversion

thanks for allowing me join your forum i have an output of linux command "who" which provides following details..... CURRENT USER/ACCT INFO 17:31:36 up 4:49, 4 users, load average: 0.03, 0.04, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root :0 - 12:59 ?xdm? 4:54 0.02s /bin/sh /usr/bi... (1 Reply)
Discussion started by: ayyappancheta
1 Replies

7. UNIX for Advanced & Expert Users

shell script to format .CSV data

Hi all, I have written a shell script to search a specified directory (e.g. /home/user) for a list of specific words (shown as ${TMPDIR}/wordlist below). The script works well enough, but I was wondering if there was a way to display the line number that the word is found on? Thanks! cat... (1 Reply)
Discussion started by: tmcmurtr
1 Replies

8. Shell Programming and Scripting

shell script to insert data from gps.txt to mysql database

Hi, I have gps receiver, by using gpsd data i can read gps log data to my database(my sql). Steps: 1. telenet localhost 2947 > gps.txt (press enter) 2. r (press enter) //then i will get the data like below in gps.txt file Trying 127.0.0.1... Connected to localhost.... (1 Reply)
Discussion started by: gudivada213
1 Replies

9. Shell Programming and Scripting

Shell script to format a .CSV data

Hi There I needed to write a Unix shell script which will pick up the data from a .CSV file and reformat it as per the requirement and write it to another .CSV file. Currently I am in the proess of Data Import to "Remedy System" (A one kind of incident mangement Application) and this... (8 Replies)
Discussion started by: Uday1982
8 Replies
Login or Register to Ask a Question