[X-Unix] parsing help?

Russell McGaha RussellMcGaha at hughes.net
Thu Apr 27 14:18:23 PDT 2006


Wing;
	I didn't originally send actual data because the lines are VERY  
long; but since it's requested:

[4lines]

"2HPC12","1/2"" CTS 2-HOLE PIPE CLAMP","1/2"" COPPER TUBE SIZE. FITS  
COPPER, CPVC, AND POLYBUTYLENE","CARTON QUANTITY ONLY",". 
01","693374000068",". 
24","2000","G-04","C612","*461260","559-2","","","H28-050","","H28-050", 
""
"","","","","","","","","","","","","","","","","16051",""
"","","","","","","","","","","","","","","","","559-2",""
"2HPC34","3/4"" CTS 2-HOLE PIPE CLAMP","3/4"" COPPER TUBE SIZE. FITS  
COPPER, CPVC, AND POLYBUTYLENE","CARTON QUANTITY ONLY",". 
01","693374000075",". 
26","1000","G-04","C634","","","","","H28-075","","H28-075",""
"","","","","","","","","","","","","","","","","16052",""
"","","","","","","","","","","","","","","","","559-3",""

Should become: [2 lines]

"2HPC12","1/2"" CTS 2-HOLE PIPE CLAMP","1/2"" COPPER TUBE SIZE. FITS  
COPPER, CPVC, AND POLYBUTYLENE","CARTON QUANTITY ONLY",". 
01","693374000068",". 
24","2000","G-04","C612","*461260","559-2","","","H28-050","","H28-050", 
"","16051","","559-2",""
"2HPC34","3/4"" CTS 2-HOLE PIPE CLAMP","3/4"" COPPER TUBE SIZE. FITS  
COPPER, CPVC, AND POLYBUTYLENE","CARTON QUANTITY ONLY",". 
01","693374000075",". 
26","1000","G-04","C634","","","","","H28-075","","H28-075","","16052"," 
","559-3",""

the pattern: [\r"","","","","","","","","","","","","","","","",]  
should become: [,]

Russell

On Apr 27, 2006, at 2:47 PM, Wing Wong wrote:

> On 4/27/06, Russell McGaha <RussellMcGaha at hughes.net> wrote:
>> All;
>>         I guess what I REALY need to do, is change the pattern
>> "<return>,,, ... ," to "," . Is there a simple way to do this?
>> because of the <return> char, I'm not sure how to correctly do this.
>>
>> Russell
>
> Russell,
>
> Can you post an actual couple of lines of the actual data and then a
> couple of lines of what you would like that data to actually look
> like? The various commas and dots are confusing to read and interpret
> accurately.
>
>> From what you just posted, I'm hearing:
>
> You have a series of lines in the exported csv file that takes the  
> form of:
>
> <CR/LF>,,,,,,,,,,,
> <CR/LF>,,,,,,,,,,,
> <CR/LF>,,,,,,,,,,,
>
> And you want to reduce the commas to a single comma?
>
> # To reduce a string of commas into one comma:
> cat source.csv | sed -e 's/[,][,]*/,/g' > single_comma.csv
>
> # To get rid of the CR/LF and reduce the string of commas to one  
> comma:
> cat source.csv | sed -e 's/[\n][,][,]*/,/g' > no_crlf_single_comma.csv
>
> Not sure if that is what you really want to do. If you are looking to
> change the order of the various parameters, you can use awk to do
> that.
>
> IF, your file is actually looking something like this:
>
> ,,,,,,,,,^M
> ,,,,,,,,,^M
> ,,,,,,,,,^M
> ,,,,,,,,,^M
>
> Ie, a an exported csv file using DOS/WIN cr/lf conventions, and you
> just want to get rid of the ^M's, but want to retain the line breaks:
>
> cat source.csv | tr '^V^M' '\012' > convertedlinefeeds.csv
> # The ^V is CTRL-V and the ^M is hitting the ENTER key after the  
> CTRL-V
>
> or, you can use the dos2unix binary to convert the linefeeds for you.
>
> But like I noted above, if you can send a sample of what the actual
> lines look like and a sample of what you'd like the lines to look
> like, it would be much easier to give example code snippets.
>
> Wing
>
> --
> Wing Wong
> wingedpower at gmail.com
> _______________________________________________
> X-Unix mailing list
> X-Unix at listserver.themacintoshguy.com
> http://listserver.themacintoshguy.com/mailman/listinfo/x-unix
>
> Listmom is trying to clean out his closets! Vintage Mac and random  
> stuff:
>          http://search.ebay.com/_W0QQsassZmacguy1984



More information about the X-Unix mailing list