Awk sub command - Prod - Urgent


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk sub command - Prod - Urgent
# 1  
Old 07-29-2011
Awk sub command - Prod - Urgent

Hi

I have this check in file for replacing text in unix .This code use to work in linux but stopped working when we moved to unix.

cat xyz.dat | awk '/\x07/{sub(/\"/,"")};{print}'|awk '/\x07/{sub(/\"\,\"/,"\x07")};{print}'|awk '/\x07/{sub(/\"\,\"/,"\x07")};{print}'|awk '/\x07/{sub(/\"\,\"/,"\x07")};{print}'| dos2unix > abc.dat

If you notice
awk '/\x07/{sub(/\"/,"")};{print}'
This command is repated

How can I fix that?

What command should I use awk in Unix so that I get desired result

Quick response appreciated.
# 2  
Old 07-29-2011
what are you trying to accomplish? can you post sample input and output? Please use code tags when posting code or sample i/oput.
Furthermore, is there any error? What exactly is your system?

Use nawk if on Solaris.

Last edited by mirni; 07-29-2011 at 08:39 PM..
# 3  
Old 07-29-2011
More details

i want to replace string ,", with octal value 007 (^G)

My file is in format .there are 5 column

"col1","col2","col3","col4","col5"

is should appear like this

col1^Gcol2^Gcol3^Gcol4^Gcol5.


Error I get

awk : Syntax error at line 1
awk : illegal statement near line 1
# 4  
Old 07-29-2011
And your system is... ?

Try this instead:
Code:
cat xyz.dat | sed 's/","/\x07/g ; s/"//g'

# 5  
Old 07-29-2011
System is

Quote:
cat xyz.dat | awk '/\x07/{sub(/\"/,"")};{print}'|awk '/\x07/{sub(/\"\,\"/,"\x07")};{print}'|awk '/\x07/{sub(/\"\,\"/,"\x07")};{print}'|awk '/\x07/{sub(/\"\,\"/,"\x07")};{print}'| dos2unix > abc.dat

SYSTEM IS SUNOS SPARC

---------- Post updated at 05:15 PM ---------- Previous update was at 05:12 PM ----------

what if i get " in my data.

this wont work

my script use to take care of it
but it doesn't work on Unix

not able to figure out why
# 6  
Old 07-29-2011
Quote:
use nawk on Solaris
Code:
cat xyz.dat | nawk '{gsub(/","/,"\x007"); gsub(/"/,"")}1'

---------- Post updated at 02:19 PM ---------- Previous update was at 02:15 PM ----------

Quote:
what if i get " in my data.

this wont work
If you are worried about quotes inside the fields, you can use anchors to strip just the first and last:
Code:
cat xyz.dat |  sed 's/","/\x07/g ; s/^"// ; s/"$//'

Quote:
my script use to take care of it
but it's a mess that could be cleaned up, for maintanence sake if for nothing else.

Sorry... I realize you are frustrated and stressed out because of the situation...

Just replace "awk" with "nawk" or "/usr/xpg4/bin/awk" and your old script should run fine.

Last edited by mirni; 07-29-2011 at 09:31 PM.. Reason: apologies
This User Gave Thanks to mirni For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Best way to point/update a file during PROD and BCP failover.

Hi All, In UNIX servers we are switching from DR to PROD. After switching to DR we need to update some configuration files which contains the server names. Ex - If we switch to BCP we need to update BCP server name. If we switch back to PROD we need to update PROD server name. I... (1 Reply)
Discussion started by: Girish19
1 Replies

2. Shell Programming and Scripting

Need to implement new CRON job or modify the existing one in MDM PROD in coming days, which will sen

Need to implement new CRON job or modify the existing one in MDM PROD in coming days, which will send email of SQL statement running from past 1 minute.Currently there is one CRON job in PROD, which send below email. there is one cron job which send email, when there is long running... (0 Replies)
Discussion started by: dampu
0 Replies

3. Red Hat

Prod runs RHEL6 but pprod uses RHEL5??

Hi, I am currently building out a new production environment. Our current prod env uses RHEL5.8 but I am thinking of building out a RHEL6 environment since a complete end-to-end testing will need to take place prior to go-live anyway. Plus it is an ideal time to upgrade the OS across the... (4 Replies)
Discussion started by: Duffs22
4 Replies

4. Shell Programming and Scripting

Urgent awk help !!

Hi All,I need to convert following field from a file L2578978CLC/576/116804 => L2578978CLC/00000576/00168304 i have to append Zeros in the third and fourth number after slash / in the above string (total length of number should be 8). means L2578978CLC/576/116804 should be converted to... (3 Replies)
Discussion started by: unknown123
3 Replies

5. AIX

-805 error in AIX UNIX accessing TEST DB from PROD

Hi, I am getting -805 error when i tried accessing TEST DB from PROD environment in AIX UNIX. Could anyone help me in this regard. Thx, Satish (1 Reply)
Discussion started by: satishstar2
1 Replies

6. UNIX for Dummies Questions & Answers

awk command behaving differntly on 2 servers--urgent

Hi I am using awk command for string replacement. I have 2 servers. The command runs perfectly well on 1st server On the second server when i run the command on the same datset The command gets stuck while processing a large piece of record.. Does it have anything to with setting on the 2... (1 Reply)
Discussion started by: aixjadoo
1 Replies

7. Programming

Migrating C Executable in UNIX from DEV to PROD

Hi Is there any specific way to FTP a C executable from DEV to PROD. We recently changed a C program compiled in DEV, created EXE and tested fine. But when we moved the EXE to PROD. It did not work. We have tried restarting the sever too. Once we put back the old Exe it starts to work again. The... (1 Reply)
Discussion started by: rainbow29
1 Replies

8. UNIX for Dummies Questions & Answers

copy prod data to QA

We keep getting production files into an input directory. These files will be processed three times a day. 8:00AM 1:30PM 5:30PM file1.20041005_05303423.dat File2.200041005_14232313.dat Once the files are processed, they are archived immediately to prod/archive directory ... (1 Reply)
Discussion started by: zomboo
1 Replies

9. Shell Programming and Scripting

What is $PROD ? Does it represent some Unix directory?

Hi , Could u tell me What is $PROD ? Does it represent some Unix directory? Regards Ashish Malviya (2 Replies)
Discussion started by: Ashishm
2 Replies
Login or Register to Ask a Question