Modify awk command to work in linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modify awk command to work in linux
# 1  
Old 11-23-2011
Modify awk command to work in linux

Hi All

I have the original file like
Code:
'1','3','COMMON','N','djpCM3PopDimDateGen','JobDescription','1','ds','O','ONE' '1','3','COMMON','N','djpCM3PopDim1','JobDescription','2','ds','O','ONE' '1','3','COMMON','N','djpCM3PopDim2','JobDescription','3','ds','O','ONE' '1','3','COMMON','N','djpCM3PopDim3','JobDescription','4','ds','O','ONE' '1','3','COMMON','N','djpCM3PopDim4','JobDescription','5','ds','O','ONE' '1','3','COMMON','N','djpCM3PopDim5','JobDescription','6','ds','O','ONE' '1','3','COMMON','N','djpCM3PopDim6','JobDescription','7','ds','O','ONE' '1','3','COMMON','N','djpCM3PopDim7','JobDescription','8','ds','O','ONE' '1','3','COMMON','N','djpCM3PopDayRollingSum','JobDescription','9','ds','O','ONE' '1','3','COMMON','N','djpCM3PopWkRollingSum','JobDescription','10','ds','O','ONE' '1','3','COMMON','N','djpCM3LangIntLoad','JobDescription','11','ds','D','DIM' '1','3','COMMON','N','djpCM3GroupIntLoad','JobDescription','12','ds','D','DIM' '1','3','COMMON','N','djpCM3BankEntityGroupIntLoad','JobDescription','13','ds','D','DIM' '1','3','COMMON','N','djpCM3ChanlComnDimIntLoad','JobDescription','14','ds','D','DIM' '1','3','COMMON','N','djpCM3ChanlEvtAllDimsIntLoad','JobDescription','15','ds','D','DIM' '1','3','COMMON','N','djpCM3ChanlEvtStatIntLoad','JobDescription','16','ds','D','DIM' '1','3','COMMON','N','djpCM3CityIntLoad','JobDescription','17','ds','D','DIM' '1','3','COMMON','N','djpCM3CtryIntLoad','JobDescription','18','ds','D','DIM' '1','3','COMMON','N','djpCM3RegionIntLoad','JobDescription','19','ds','D','DIM' '1','3','COMMON','N','djpCM3TimeZoneIntLoad','JobDescription','20','ds','D','DIM' '1','3','COMMON','N','djpCM3DeviceIntLoad','JobDescription','21','ds','D','DIM' '1','3','COMMON','N','djpCM3PostalAddrLoad','JobDescription','22','ds','D','DIM' '1','3','COMMON','N','djpCM3PostalAddrDeviceLoad','JobDescription','23','ds','D','DIM' '1','3','COMMON','N','djpCM3EmplyIntLoad','JobDescription','24','ds','D','DIM' '1','3','COMMON','N','djpCM3CustIntLoad','JobDescription','25','ds','D','DIM' '1','3','ACCOUNTOPENING','N','djpCM3ApeLogDeleteStage','JobDescription','26','ds','D','DIM' '1','3','ACCOUNTOPENING','X','djpCM3PopDimAcctOwnType','JobDescription','27','ds','D','DIM'


I tried to use code in linux like
Code:
`echo ${data2} | awk '{if (substr($1,0,1) == "\047") gsub("^\047+|\047+$", "", $0); gsub("\047,\047"," ",$0); print}'`

But it gives me output like

Code:
1 3 COMMON N djpCM3PopDimDateGen JobDescription 1 ds O ONE' '1 3 COMMON N djpCM3PopDim1 JobDescription 2 ds O ONE' '1 3 COMMON N djpCM3PopDim2 JobDescription 3 ds O ONE' '1 3 COMMON N djpCM3PopDim3 JobDescription 4 ds O ONE' '1 3 COMMON N djpCM3PopDim4 JobDescription 5 ds O ONE' '1 3 COMMON N djpCM3PopDim5 JobDescription 6 ds O ONE' '1 3 COMMON N djpCM3PopDim6 JobDescription 7 ds O ONE' '1 3 COMMON N djpCM3PopDim7 JobDescription 8 ds O ONE' '1 3 COMMON N djpCM3PopDayRollingSum JobDescription 9 ds O ONE' '1 3 COMMON N djpCM3PopWkRollingSum JobDescription 10 ds O ONE' '1 3 COMMON N djpCM3LangIntLoad JobDescription 11 ds D DIM' '1 3 COMMON N djpCM3GroupIntLoad JobDescription 12 ds D DIM' '1 3 COMMON N djpCM3BankEntityGroupIntLoad JobDescription 13 ds D DIM' '1 3 COMMON N djpCM3ChanlComnDimIntLoad JobDescription 14 ds D DIM' '1 3 COMMON N djpCM3ChanlEvtAllDimsIntLoad JobDescription 15 ds D DIM' '1 3 COMMON N djpCM3ChanlEvtStatIntLoad JobDescription 16 ds D DIM' '1 3 COMMON N djpCM3CityIntLoad JobDescription 17 ds D DIM' '1 3 COMMON N djpCM3CtryIntLoad JobDescription 18 ds D DIM' '1 3 COMMON N djpCM3RegionIntLoad JobDescription 19 ds D DIM' '1 3 COMMON N djpCM3TimeZoneIntLoad JobDescription 20 ds D DIM' '1 3 COMMON N djpCM3DeviceIntLoad JobDescription 21 ds D DIM' '1 3 COMMON N djpCM3PostalAddrLoad JobDescription 22 ds D DIM' '1 3 COMMON N djpCM3PostalAddrDeviceLoad JobDescription 23 ds D DIM' '1 3 COMMON N djpCM3EmplyIntLoad JobDescription 24 ds D DIM' '1 3 COMMON N djpCM3CustIntLoad JobDescription 25 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3ApeLogDeleteStage JobDescription 26 ds D DIM' '1 3 ACCOUNTOPENING X djpCM3PopDimAcctOwnType JobDescription 27 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimAppReasonCde JobDescription 28 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimAppStat JobDescription 29 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimBusProc JobDescription 30 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimExchRate JobDescription 31 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimFnlSeq JobDescription 32 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimJrnyCde JobDescription 33 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimKPICde JobDescription 34 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimAdvt JobDescription 35 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimMedia JobDescription 36 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimCamp JobDescription 37 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimProd JobDescription 38 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimProd1 JobDescription 39 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimWebAddr JobDescription 40 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimPromo JobDescription 41 ds D DIM' '1 3 ACCOUNTOPENING N djpCM3PopDimProdPromoReln JobDescription 42 ds D DIM'

From this output i want the single quotes also to be removed but the single space should be maintained.

e.g
Code:
1 3 COMMON N djpCM3PopDimDateGen JobDescription 1 ds O ONE 1 3 COMMON N djpCM3PopDim1 JobDescription 2 ds O ONE 1 3 COMMON N djpCM3PopDim2 JobDescription 3 ds O ONE 1 3 COMMON N djpCM3PopDim3 JobDescription 4 ds O ONE

I am working in the linux environment.

Could you all please help me out with command.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 11-23-2011 at 11:43 AM.. Reason: code tags, please!
# 2  
Old 11-23-2011
I made a UNIX text file called "junk" (Solaris 8 in this case):
Code:
$ cat junk
'1','3','soho garden','tribeca','9','uptown storage'

Then I used "tr" to eliminate the single quotes with a pipe into awk (using the comma as the field separator):

Code:
$ cat junk | tr -d \' | awk 'BEGIN { FS=","; } { print $3; }'
soho garden

Unless you need a variable to be set, you would not need the "`" (sub-command ticks).

Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples, thank you.

Last edited by Franklin52; 11-24-2011 at 01:40 PM..
# 3  
Old 11-23-2011
Hi,
Thanks for the reply, but i need something related to my existing code.
# 4  
Old 11-24-2011
Hi again,

Ok ... I will offer another idea ...

Since it looks as if you're using awk for the whole line of text instead of printing one or more pieces ( print $0 as opposed to print $1,$2,etc ) ... here's what I would suggest instead of using awk at all:
Code:
echo ${data2} | tr -d "'" | tr "," " "

That will produce the output that you're probably looking to see.

But, the surrounding ticks (`) indicate doing this as a sub-child process. In that case you may lose your spacing since the "IFS" variable doesn't necessarily export. So, if you decide to do:
Code:
`echo ${data2} | tr -d "'" | tr "," " "`

then be sure to:
Code:
export IFS

first.

Hope that helps ya ... happy Thanksgiving

Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples, thank you.

Last edited by Franklin52; 11-24-2011 at 01:41 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed, awk or another bash command to modify string with the content of another file

Hello everybody, I would like modify some strings using sed or another command line with the content file. For example: - {fqdn: "server-01" , ip: "server-01"} - {fqdn: "server-02" , ip: "server-02"} - {fqdn: "server-03" , ip: "server-03"} - {fqdn: "server-04" , ip: "server-04"} My... (4 Replies)
Discussion started by: dco
4 Replies

2. Shell Programming and Scripting

awk modify string

Hi Guys, i world like to do the following with awk, i have the the complete username example in a file a have some names Mario Rossi John Doe i would like to convert this name in this format from file with awk Mario,Rossi,"Mario Rossi ",m.rossi_ext@mydomain.com,$TRUE, John,Doe,"John... (7 Replies)
Discussion started by: charli1
7 Replies

3. Shell Programming and Scripting

Help -- Modify awk command to handle "," delimiter

Currently I am using this command to split a CSV file based on the distinct values in the 16th (position) column. awk -F, 'NR==1 { hdr=$0; next } $16 != prev { prev=name=$16; gsub(/_]/,"",name); $0 = hdr "\n" $0 } { print > ("/Directory/File."name".Download.csv") }'... (3 Replies)
Discussion started by: lojkyelo
3 Replies

4. Linux

SQLLDR file not able to modify in Linux

Hi All I am trying to modifying SQLLDR file in Linux, I’m getting the below error "counterparty.sqlldr" E506: Can't write to backup file (add ! to override) Press ENTER or type command to continue Can someone help me resove this issue. Thank (1 Reply)
Discussion started by: na.dharma
1 Replies

5. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

6. Shell Programming and Scripting

modify awk

awk "BEGIN {if($PERCENT<$WARNING) {print \"OK\" ; exit 0} else if(($PERCENT>=$WARNING) && ($PERCENT<$CRITICAL)) {print \"WARNING\" ; exit 1} else if($PERCENT>=$CRITICAL) {print \"CRITICAL\" ; exit 2} }" how can i... (1 Reply)
Discussion started by: SkySmart
1 Replies

7. Shell Programming and Scripting

AWK command working different in Linux

Hi All I have fired a command in linux table=`echo ${file_name} | awk '{FS="/"; print $NF}' | awk '{FS="."; print $1}'` where file_name has /data/ds/dpr_ebicm_uat/backfill/temp/etl_app_info.csv /data/ds/dpr_ebicm_uat/backfill/temp/etl_app_jobs.csv ... (10 Replies)
Discussion started by: vee_789
10 Replies

8. Programming

How to modify all Makefiles in a source tree into linux environment

Hi Frndz, I am new to the makefile generation. I have a source code which contains makefiles in each sub-directories. Previously we have used the entire source code in Dtbuild environment to get the executables. Now have to change the current Dtbuild environment to Linux build... (1 Reply)
Discussion started by: korraag
1 Replies

9. Shell Programming and Scripting

Modify Perl script to work with txt - Permissions script

Hi I have this code, and i want work with a ls -shalR output in .txt What i need read to do this?? Where start? #!/usr/bin/perl # Allrights- A perl tool for making backups of file permissions # Copyright (C) 2005 Norbert Klein <norbert@acodedb.com> # This program is free... (1 Reply)
Discussion started by: joangopan
1 Replies

10. UNIX for Dummies Questions & Answers

Modify semaphores parameters on Linux

Hello, I need to modify the semaphores parameters on a Linux server Debian 2.2.R3. How can I do it? Thks. (6 Replies)
Discussion started by: annececile
6 Replies
Login or Register to Ask a Question