SUBSEP Seperator problem with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SUBSEP Seperator problem with awk
# 1  
Old 05-26-2009
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  
Old 05-26-2009
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  
Old 05-26-2009
you're using a SUBSEP as a string, and not as a builtin variable - loose the double quotes.
# 4  
Old 05-26-2009
Quote:
Originally Posted by vgersh99
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Field seperator with awk

Hi, input data format: echo ' <APPLICATION="APPLSG" SUB_APPLICATION="DLY" JOBNAME="DPL_BN_RE_CCMS_SA" CMDLINE="run_job.ksh %%PARAM1 %%PARAM2" TASKTYPE="Command" />' expected format: "APPLSG", "DLY", "DPL_BN_RE_CCMS_SA", "run_job.ksh %%PARAM1 %%PARAM2" my command: echo ' ... (2 Replies)
Discussion started by: JSKOBS
2 Replies

2. Shell Programming and Scripting

How to replace only \n( line seperator ) not Data \n?

Unix File is pipe delimited with 17 fields. We may get extra pipes in data also. We may get \n char (1 or more \n in one field or multi fileds) in data in any field. Need to replace \n true ( line separator) with 'space and bell char space' chars (' \a ') Not data \n. Input:... (1 Reply)
Discussion started by: rajeshkumare
1 Replies

3. Shell Programming and Scripting

field seperator question (awk script)

Is there a way I could use different a different field seperator for different parts of the body? kinda like {FS = ":"} FILENAME == "products"{ price = $3 if(numprods < $1-100) numprods = $1-100 } {FS = "/"}{} FILENAME == "associates"{ associateid... (5 Replies)
Discussion started by: angermanaged
5 Replies

4. Shell Programming and Scripting

Printing value with no obvious field seperator

Hi all, Can anybody think of a way to do this? I have a file with content like the following: F_TOP_PARAM_VALUEF_TOP_SOURCEF_TOP_DEL_NOTIFICATIONF_DEST_ADDRF_TOP_DEL_TYPE What I want to do is print out the value in the square brackets after F_TOP_SOURCE. So in this case I'd like to print... (4 Replies)
Discussion started by: Donkey25
4 Replies

5. Shell Programming and Scripting

How to change field seperator

Hi Please help me out with this problem: I want to have a script that would change the nth field seperator in a line into something else. like a,d,4,2,97,8,9 into a,d,4,2,97/8/9 Thanks (2 Replies)
Discussion started by: onthetopo
2 Replies

6. Shell Programming and Scripting

regexp to print after a field seperator

Hi, How do i Print anything after a ':' Ex : file1: 1235131(rs32553) I want to print out "1235131(rs32553)" how do i do it. I know we can do this using awk but looking for the right syntax. Any help appreciated. Thanks, Ram (7 Replies)
Discussion started by: ramky79
7 Replies

7. UNIX for Dummies Questions & Answers

Using | as a seperator in join

I need to use | as a seperator in unix join command. i tried changing seperator using -t option but iit is not working. can u please help. (5 Replies)
Discussion started by: firvin
5 Replies

8. Shell Programming and Scripting

Comma seperator

I am trying to create a new CSV file from an existing CSV file whose content is as follows: "1","Tom,Garry","111" "2","Tom,Garry","222" when i use Cat file | cut -d',' -f1,3 or awk to have only the 1st and 3rd column in my new CSV file, instead of creating a file content as "1","111"... (6 Replies)
Discussion started by: premar
6 Replies

9. Solaris

how i can use a WORD for seperator

hi, i want to use A WORD for seperator in awk or especially in cut. how i can perform this. is there any way to use a word for seperator. For example: i want to list all word after FROM and the files name contains this word. chatnorollback.svc: delete from info where nick ... (3 Replies)
Discussion started by: qrshat
3 Replies

10. Shell Programming and Scripting

Awk Field Seperator Help

I wrote a script on HPUX 11.11 to turn a Decimal subnet mask (255.255.254.0) to hex 0xfffffe00 (subset of a bigger script). It works great on the HPUX systems but on the freebsd box the awk is not seperating the fields properly. I tried to google for a solution and seaching these forums i am just... (3 Replies)
Discussion started by: insania
3 Replies
Login or Register to Ask a Question