The UNIX and Linux Forums  


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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to change field seperator onthetopo Shell Programming and Scripting 2 05-11-2007 01:11 PM
Using | as a seperator in join firvin UNIX for Dummies Questions & Answers 5 03-28-2006 12:23 PM
Comma seperator premar Shell Programming and Scripting 6 02-17-2006 04:16 AM
how i can use a WORD for seperator qrshat SUN Solaris 3 02-10-2006 07:08 AM
Awk Field Seperator Help insania Shell Programming and Scripting 3 11-11-2005 04:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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

  #2 (permalink)  
Old 05-26-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,800
SUBSEP is a comma by default that is what \034 is. Just use ","

Can you not format your output with printf( format-string, [value], ...);
  #3 (permalink)  
Old 05-26-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
you're using a SUBSEP as a string, and not as a builtin variable - loose the double quotes.
  #4 (permalink)  
Old 05-26-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
Quote:
Originally Posted by vgersh99 View Post
you're using a SUBSEP as a string, and not as a builtin variable - loose the double quotes.

Thanks Vgersh99.

jim mcnamara--
Quote:
echo "," | od -bc
0000000 054 012
, \n
0000002
Comma octal value is 054.
Any way subsep works for now.
Thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0