The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 05-26-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
SUBSEP Seperator problem with awk

The following code removes new line with in double quotes
I am replacing newline character with in double quotes with 123.
Code:
intermediatenewline_remover () {
    typeset Infile=$1
    nawk -F"," '{ record = record $0
 if ( gsub( /"/, "&", record ) % 2 ) 
 {
     record = record "123"
     next
 }
    }
    { 
 print record
 record = ""
    }' Infile
}
Here i am combining 4th and 5th field with "123" as seperator
Code:
    nawk -F"|" '{print $2,$3,$4"123"$5}' OFS="|" file
Replacing Comma and seperator "123" with space.
The problem here is if data has "123" that will also be replaced with space.
I want only "123" seperator to be replaced.

Code:
    nawk -F"|" '{gsub(",", " ",$3);gsub("123", " ",$3);print}' OFS="|" file
I tried using SUBSEP
This code instead of using value for SUBSEP "\034" its inserting "SUBSEP"

Code:
intermediatenewline_remover () {
    typeset Infile=$1
    nawk -F"," '{ record = record $0
 if ( gsub( /"/, "&", record ) % 2 ) 
 {
     record = record "SUBSEP"
     next
 }
    }
    { 
 print record
 record = ""
    }' Infile
}
and how to handle this change in this code

Code:
    nawk -F"|" '{print $2,$3,$4"123"$5}' OFS="|" file
    nawk -F"|" '{gsub(",", " ",$3);gsub("123", " ",$3);print}' OFS="|" file