Shell script to correct the data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to correct the data
# 1  
Old 04-18-2014
Shell script to correct the data

Hi,

I have below data in my flat file.I would like to remove the quotes and comma necessary from the data.Below is the details I would like to have in my output.

Could anybody help me providing the Unix shell script for this.

Input :

Code:
ABC,ABC,10/15/2012,"47,936,164.567 ","1,036,997.453 ",0 ,"48,973,162 ",,0 ,,,"18,352,692.981 ","397,022.786 ",,"18,749,714 ",,,,,,

Output :

Code:
ABC,ABC,10/15/2012,47936164.567 ,"1036997.453 ",0 ,"48,973,162 ",,0 ,,,18352692.981 ,397022.786 ,,"18,749,714 "

Moderator's Comments:
Mod Comment Please use CODE tags (not QUOTE tags) to display sample input, output, and code segments.

Last edited by Don Cragun; 04-18-2014 at 03:09 PM.. Reason: Fix tags.
# 2  
Old 04-18-2014
I couldn't understand the requirement correctly
The below output you have provided have quotes and unnecessary commas
Code:
ABC,ABC,10/15/2012,47936164.567 ,"1036997.453 ",0 ,"48,973,162 ",,0 ,,,18352692.981 ,397022.786 ,,"18,749,714 "

How do you know which quote is necessary and how to you know the commas in last number are required

---------- Post updated at 07:11 AM ---------- Previous update was at 07:07 AM ----------

But, if you want to remove all quotes and unnecessary commas, use the below code
Code:
awk -F "\"" '{for(i = 2; i <= NF; i += 2)
  {gsub(",", X, $i)}; out = $1
  for(i = 2; i <= NF; i++) {out = (out $i)};
  print out}' file | sed 's/,\{1,\}$//'

# 3  
Old 04-18-2014
Your requirements are ambiguous and this sounds like a homework assignment. If this is a homework assignment, you have been told before about the rules for filing homework assignments.

If this is not a homework assignment, please describe the project you are working on that requires this software AND clearly describe the criteria that determines whether or not a comma in your input is "necessary".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display calendar in correct format using shell script

Hi All, I'm trying to print calendar using shell script and i'm able to print it. But the format is not good. Here is the script. #!/bin/bash echo $(date) echo "Hello $USER" echo Hostname $(hostname) echo Working in $(pwd) echo Here is this month calender echo $(cal) $ sh first.sh... (7 Replies)
Discussion started by: chandrakanth
7 Replies

2. Shell Programming and Scripting

Auto correct a csv file using UNIX shell script.

Hi All, There are list of 4-5 .csv files which has 12 columns.In some cases one of the record is split into 2 records. What needs to be done is this split record has to be auto corrected and placed in the csv file. Eg: Let us consider sample.csv file and in normal conditions the file would... (40 Replies)
Discussion started by: karthik_ak
40 Replies

3. Post Here to Contact Site Administrators and Moderators

Auto correct a csv file using UNIX shell script.

Hi All, There are list of 4-5 .csv files which has 12 columns.In some cases one of the record is split into 2 records. What needs to be done is this split record has to be auto corrected and placed in the csv file. Eg: Let us consider sample.csv file and in normal conditions the file... (1 Reply)
Discussion started by: karthik_ak
1 Replies

4. Shell Programming and Scripting

Correct shell script to Call One shell script from another shell script

Hi All, I have new for shell scripting. Problem : I have one scrip at serv1 and path of server is /apps/dev/provimage/scripts and script name:extract_ancillary.bat. I need to call this script at server2(my working server) and execute at server2 . Please let me know how to build the... (5 Replies)
Discussion started by: Vineeta Nigam
5 Replies

5. Shell Programming and Scripting

Help to get correct data using awk

I have this input.|user1 |10.10.10.10 |23|046|1726 (212) |0 |user2 |10.10.10.11 |23|046|43 (17) |0 |test |10.10.10.12 |23|046|45 (10) |0 |test1 |10.10.10.13 |23|046|89 (32) |0 I need to get the data for a user like thisuser1 1726 user2 43 test 45 test1 89... (11 Replies)
Discussion started by: Jotne
11 Replies

6. UNIX for Advanced & Expert Users

Convert column data to row data using shell script

Hi, I want to convert a 3-column data to 3-row data using shell script. Any suggestion in this regard is highly appreciated. Thanks. (4 Replies)
Discussion started by: sktkpl
4 Replies

7. Shell Programming and Scripting

Not correct processing of “\ “ in names of dirs inside shell script (tar command - system backup scr

Hello, Recently, I've started with shell scripting, and decided to write a script for my system backup using tar. When I was dealing with tar execution inside shell script I found this, inside shell we have the following code: tar $TAR_PARAMS $ARCHIVE_FILE $EXCLUDE $BACKUP_STARTwith... (6 Replies)
Discussion started by: ilnar
6 Replies

8. Shell Programming and Scripting

how to get the correct alignment in a textfile to a mail using shell script?

Hi All, Can any one solve this prob. Im sending a textfile content as a mail body while sending a mail using shell script. But, that textfile content is a unic command output. So, in mail, im not getting the correct alignment as in textfile. What may be the reason behind this. Can... (1 Reply)
Discussion started by: suman_dba1
1 Replies

9. Shell Programming and Scripting

Plz correct my syntax of shell script

Dear all I am still bit new in shell script area.I am writing down a shell script which I guess somewhere wrong so please kindly correct it. I would be greatful for that. What I actually want from this shell script is that it will move all the files one by one to another server which can be... (2 Replies)
Discussion started by: girish.batra
2 Replies

10. Shell Programming and Scripting

Correct Syntax For Calling Shell Script in Perl Module

Problem: I have a shell script that will be called by a Perl module that will connect to a db and delete rows. The Perl module will be called by CRON. I am using a Perl module to call a shell script because I need to get the db connection from Perl. Here is the Perl pseudocode: ... (4 Replies)
Discussion started by: mh53j_fe
4 Replies
Login or Register to Ask a Question