Home Man
Search
Today's Posts
Register

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

Remove two delimiters, space and double quotes

Tags
beginners

 

 
Thread Tools Search this Thread
# 1  
Old 01-11-2012
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 08:38 AM.. Reason: code tags
# 2  
Old 01-11-2012
Code:
 
sed 's#^"##g;s# "#\^_#g;s#" #\^_#g'

# 3  
Old 01-11-2012
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 01-11-2012
@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.
# 5  
Old 01-11-2012
Code:
perl -pe 's/ /\037/g;s/"//g' input.txt

 

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To remove double quotes from specific columns Krishnanth S UNIX for Beginners Questions & Answers 6 02-10-2018 11:04 AM
Remove Carriage Return (CRLF) within double quotes covina Shell Programming and Scripting 12 07-27-2015 01:51 PM
Remove pipe(|) symbol in except the ones which are enclosed in double quotes Sathyapts Shell Programming and Scripting 9 06-25-2015 02:31 PM
Remove pipe(|) symbol ina file, except the ones which are enclosed in double quotes Sathyapts Shell Programming and Scripting 1 06-24-2015 05:58 PM
Replace Double quotes within double quotes in a column with space while loading a CSV file mlavanya Shell Programming and Scripting 6 05-12-2015 12:05 AM
Skip the delimiter with in double quotes and count the number of delimiters during data extract BrahmaNaiduA Shell Programming and Scripting 2 02-03-2015 10:38 PM
Trying to remove double quotes Saanvi1 Shell Programming and Scripting 8 01-06-2014 12:25 PM
Replace newline character between a double quotes to a space ajahuja Shell Programming and Scripting 8 08-02-2012 10:43 AM
How to remove a character which is enclosed in Double quotes mohan_tuty UNIX for Advanced & Expert Users 3 06-16-2008 11:55 AM
Remove double quotes deepakwins UNIX for Dummies Questions & Answers 3 05-30-2008 11:53 AM


All times are GMT -4. The time now is 01:24 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password