Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Remove two delimiters, space and double quotes

UNIX for Dummies Questions & Answers


 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-11-2012   -   Original Discussion by SteveDWin
SteveDWin SteveDWin is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 11 January 2012, 10:50 AM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Remove two delimiters, space and double quotes

I would like to know how to replace a space delimiter with a ^_ (\037) delimiter and a double quote delimiter while maintaining the spaces inside the double quotes. The double quote delimiter is only used on text fields.
I'd prefer a one-liner, but could handle a function or script that accepts the filename and delimiter as arguments

I have a txt file that looks like this:
"#04274DV1!" 414 "104274DV1" 04/30/09 1.25 "BRK CD 104274DV1" "BROKERED CD 1.25 04/30/2009" "RAVE BANK $2,590,000.00" "" ? 01/30/09 0 "t" "n" 0 "" ? 0 ? ? "mo" 30 "h"

and I want it to look like (:

#04274DV1!^_414^_104274DV1^_04/30/09^_1.25^_BRK CD 104274DV1^_BROKERED CD 1.25 04/30/2009^_RAVE BANK $2,590,000.00^_^_?^_01/30/09^_0^_t^_n^_0^_^_?^_0^_?^_?^_mo^_30^_h

Last edited by SteveDWin; 01-11-2012 at 09:38 AM.. Reason: code tags
Sponsored Links
    #2  
Old Unix and Linux 01-11-2012   -   Original Discussion by SteveDWin
max_hammer max_hammer is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 24 September 2015, 9:27 AM EDT
Location: Neverland
Posts: 60
Thanks: 12
Thanked 11 Times in 10 Posts

Code:
 
sed 's#^"##g;s# "#\^_#g;s#" #\^_#g'

Sponsored Links
    #3  
Old Unix and Linux 01-11-2012   -   Original Discussion by SteveDWin
pandeesh's Unix or Linux Image
pandeesh pandeesh is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 27 September 2015, 12:56 AM EDT
Posts: 324
Thanks: 80
Thanked 12 Times in 12 Posts
This works as expected:

Code:
pandeeswaran@ubuntu:~/training$ cat samp
"#04274DV1!" 414 "104274DV1" 04/30/09 1.25 "BRK CD 104274DV1" "BROKERED CD 1.25 04/30/2009" "RAVE BANK $2,590,000.00" "" ? 01/30/09 0 "t" "n" 0 "" ? 0 ? ? "mo" 30 "h" 
pandeeswaran@ubuntu:~/training$ cat samp|sed -e "s/^\"//g" -e "s/\" /\^_/g" -e "s/ \"/\^_/g" -e "s/\^_$//" -e "s/\"//g"
#04274DV1!^_414^_104274DV1^_04/30/09 1.25^_BRK CD 104274DV1^_BROKERED CD 1.25 04/30/2009^_RAVE BANK $2,590,000.00^_^_? 01/30/09 0^_t^_n^_0^_^_? 0 ? ?^_mo^_30^_h

    #4  
Old Unix and Linux 01-11-2012   -   Original Discussion by SteveDWin
methyl methyl is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 8 June 2016, 9:58 PM EDT
Posts: 6,402
Thanks: 288
Thanked 676 Times in 645 Posts
@pandeesh
The short notation ^_ refers to the control code Ctrl/_ which equates to Octal 037 (Hexadecimal 1F). Not a popular choice of field delimiter.

Though this task is relatively easy in a high-level language, the embedded spaces in the original quotes delimited fields makes the task difficult in Shell programming.

Another post where it has to be easier to repair the program which wrote the file.
Sponsored Links
    #5  
Old Unix and Linux 01-11-2012   -   Original Discussion by SteveDWin
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 8 November 2017, 2:32 AM EST
Location: India
Posts: 1,976
Thanks: 31
Thanked 574 Times in 547 Posts

Code:
perl -pe 's/ /\037/g;s/"//g' input.txt

Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to remove extra double quotes from string in a delimited file?? BICC Shell Programming and Scripting 2 07-07-2011 02:50 PM
How to ignore delimiters inside the quotes? Ganesh Khandare Shell Programming and Scripting 7 10-12-2010 07:24 AM
How to remove a character which is enclosed in Double quotes mohan_tuty UNIX for Advanced & Expert Users 3 06-16-2008 12:55 PM
Remove double quotes deepakwins UNIX for Dummies Questions & Answers 3 05-30-2008 12:53 PM
remove files with 0 size, space and double qoute nongrad Shell Programming and Scripting 3 02-08-2002 03:32 PM



All times are GMT -4. The time now is 07:15 PM.