Sponsored Content
Top Forums Shell Programming and Scripting Escaping specific character in awk Post 302162124 by brainyoung on Monday 28th of January 2008 05:07:41 AM
Old 01-28-2008
Error Escaping specific character in awk

Hello there,

I have a bit of dirty delimited file, I mentioned dirty because, the delimiter can also appear in wrong positions. However, one uniqueness of this file is
whenever the delimiter appear inside the double quote, then do not consider as delimiter, if it appear outside double then consider it as delimiter.


contents looks like below

abc;def;ghi;"kl;mn;op" ;qrst;uv;w;xyz;

AWk

inp=$1
nawk -F";" '{ print $1"~"$2"~"$3"~"$4"~"$5"~"$6"~"$7"~"$8; }' $inp >> ${inp}_det.txt

gives me ouptut as

abc ~def~ghi~"kl~mn~op" ~qrst~uv

But expected output is

abc ~def~ghi~"kl;mn;op" ~qrst~uv~w~xyz


I'm kind of stuck how to escape the double quote . I appreciate any pointers.

thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Escaping the * character in ksh.

Hi All, In ksh script i'm trying to assign "sqlstmt1" varaible value, update VAREntryTb set VAR10num = VAR1num * Mltplr where BusD = '$val1' and RunI = 1"` Hence i wrote below statement, the issue with this is shell is expanding "*" character adn thus subistuting it with the content of my... (6 Replies)
Discussion started by: arvindcgi
6 Replies

2. UNIX for Advanced & Expert Users

Escaping special character stored in variables : perl

Hi just for regular use i m working on small module written in perl for getting date in specified format like i have to specify date format and then seperator to seperate date i am 95% done. now i m sure explanation i gave is not good enough so i am putting output here : C:\Documents and... (2 Replies)
Discussion started by: zedex
2 Replies

3. Shell Programming and Scripting

Using sed to replace specific character and specific position

I am trying to use sed to replace specific characters at a specific position in the file with a different value... can this be done? Example: File: A0199999123 A0199999124 A0199999125 Need to replace 99999 in positions 3-7 with 88888. Any help is appreciated. (5 Replies)
Discussion started by: programmer22
5 Replies

4. Shell Programming and Scripting

AWK Print Line If Specific Character Is Matched

Hello, I have a file as such: FFFFFFF6C000000 225280 225240 - - rwxs- FFFFFFFF79C00000 3240 3240 - - rwxs- FFFFFFFF7A000000 4096 4096 - - rwxs- FFFFFFFF7A400000 64 64 ... (3 Replies)
Discussion started by: PointyWombat
3 Replies

5. Shell Programming and Scripting

File character adjustment based on specific character

i have a reqirement to adjust the data in a file based on a perticular character the sample data is as below 483PDEAN CORRIGAN 52304037528955WAGES 50000 89BP ABCD MASTER352 5434604223735428 4200 58BP SOUTHERN WA848 ... (1 Reply)
Discussion started by: pema.yozer
1 Replies

6. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

7. Shell Programming and Scripting

sed - replacement file path with variable - Escaping / character

Hi,, I have the line below in a file: $!VarSet |LFDSFN1| = '"E:\APC\Trials\20140705_427_Prototype Trial\Data\T4_20140705_Trial_Cycle_Data_13_T_Norm.txt" "VERSION=100 FILEEXT=\"*.txt\" FILEDESC=\"General Text\" "+""+"TITLE{SEARCH=NONE NAME=\"New Dataset\" LINE=1I want to write a script to change... (2 Replies)
Discussion started by: carlr
2 Replies

8. UNIX for Advanced & Expert Users

Replace certain character at specific place with related character

hello i have file with 100k records and each one has certain value that starts at 28th column and certain value that starts at 88th column e.g. 1st file <25>1234567 ..... <88> 8573785485 i have aditional file with values which are related to value that starts at 88th column of the... (1 Reply)
Discussion started by: dell1520
1 Replies

9. Shell Programming and Scripting

Add character to specific columns using sed or awk and make it a permanent change

Hi, I am writing a shell script where I want that # should be added in all those lines as the first character where the pattern matches. file has lot of functions defined a.sh #!/bin/bash fn a { beautiful evening sunny day } fn b { } fn c { hello world .its a beautiful day ... (12 Replies)
Discussion started by: ashima jain
12 Replies

10. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies
STRSEP(3)						   BSD Library Functions Manual 						 STRSEP(3)

NAME
strsep -- separate strings LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <string.h> char * strsep(char **stringp, const char *delim); DESCRIPTION
The strsep() function locates, in the string referenced by *stringp, the first occurrence of any character in the string delim (or the termi- nating '' character) and replaces it with a ''. The location of the next character after the delimiter character (or NULL, if the end of the string was reached) is stored in *stringp. The original value of *stringp is returned. An ``empty'' field (i.e., a character in the string delim occurs as the first character of *stringp) can be detected by comparing the loca- tion referenced by the returned pointer to ''. If *stringp is initially NULL, strsep() returns NULL. EXAMPLES
The following uses strsep() to parse a string, and prints each token in separate line: char *token, *string, *tofree; tofree = string = strdup("abc,def,ghi"); assert(string != NULL); while ((token = strsep(&string, ",")) != NULL) printf("%s ", token); free(tofree); The following uses strsep() to parse a string, containing tokens delimited by white space, into an argument vector: char **ap, *argv[10], *inputstring; for (ap = argv; (*ap = strsep(&inputstring, " ")) != NULL;) if (**ap != '') if (++ap >= &argv[10]) break; SEE ALSO
memchr(3), strchr(3), strcspn(3), strpbrk(3), strrchr(3), strspn(3), strstr(3), strtok(3) HISTORY
The strsep() function is intended as a replacement for the strtok() function. While the strtok() function should be preferred for portabil- ity reasons (it conforms to ISO/IEC 9899:1990 (``ISO C90'')) it is unable to handle empty fields, i.e., detect fields delimited by two adja- cent delimiter characters, or to be used for more than a single string at a time. The strsep() function first appeared in 4.4BSD. BSD
December 5, 2008 BSD
All times are GMT -4. The time now is 01:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy