Help required in UNIX commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help required in UNIX commands
# 1  
Old 06-03-2016
Help required in UNIX commands

I have 40000 records in a file where i need to change the 7th field date format from 05142016 [ MMDDYYY] to 20160514 [YYYYMMDD]

I have given field below. any help would be highly appreciated.

Code:
364512|9999999|9999999|210553|195495477|195257095|05142016|10009|36313

---------- Post updated at 05:02 AM ---------- Previous update was at 04:53 AM ----------

example of the records:

Code:
364512|9999999|9999999|34772|195490568|195165437|05142016|10104|54321|0121204|00028200001795|00028200004789|407347602|MANUFACTURER BILL BACK|-1|0|0|1|0|||||||||||
364512|9999999|9999999|34772|195190116|195190116|05142016|10104|54356|0121094|00027200008629|00027200008629|40107|MCLANE GROC BT ME|51.56|44|10|0|0|||||||||||
364512|9999999|9999999|34772|195190116|195190116|05142016|10104|54356|0121094|00027200008629|00027200008629|407347602|MANUFACTURER BILL BACK|-12|0|0|1|0|||||||||||
364512|9999999|9999999|34772|195190118|195190118|05142016|10104|54358|0121063|00027200008650|00027200008650|40107|MCLANE GROC BT ME|103.12|88|20|0|0|||||||||||
364512|9999999|9999999|34772|195190118|195190118|05142016|10104|54358|0121063|00027200008650|00027200008650|407347602|MANUFACTURER BILL BACK|-24|0|0|1|0|||||||||||

---------- Post updated at 05:02 AM ---------- Previous update was at 05:02 AM ----------

7th field need to be globally replaced as 05142016 to 20160514.

---------- Post updated at 05:22 AM ---------- Previous update was at 05:02 AM ----------

i have used this command to find the file.

but i dont know how to replace the field 7th.

Code:
awk 'BEGIN {FS="|"} $7 == "05152016" {print $7}' filename

# 2  
Old 06-03-2016
Hello arun888,

Could you please try following.
Code:
 awk -F"|" '{sub("05142016","20160514",$7);print}' OFS="|"   Input_file

Thanks,
R. Singh
# 3  
Old 06-03-2016
i have tried the below command.

Code:
awk 'BEGIN { FS=OFS="|"}$7=="05142016"{$7="20160415"}1' VMD_FILE.dat_bkpkktest > VMD_FILE.dat_prd

---------- Post updated at 06:16 AM ---------- Previous update was at 06:14 AM ----------

thanks ravinder for your help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help required in disabling commands.

I want to disable following commands in my linux distribution (Thanks to Linux hardening guide) # which rcp /usr/kerberos/bin/rcp # which rlogin /usr/kerberos/bin/rlogin # which rsh /usr/kerberos/bin/rsh When checked they were all part of krb5-workstation-1.6.1-25.el5 rpm. # rpm -qf... (2 Replies)
Discussion started by: pinga123
2 Replies

2. Solaris

Unix Fresher Help Required

Hello Everyone, I Am a Fresher in Unix Administrator,its About 1.5 Year Since i completed My Education And am well versed in Unix Administration.But i Am looking for some help About What i Should Mention in my resume that what i did in that past time.Suppose if am Adding fake Experience then... (2 Replies)
Discussion started by: replyazim
2 Replies

3. Solaris

Required list of all basic commands for a beginners

I want the commands list to view only files, and only directories and all the basic commands for a beginner of solaris (1 Reply)
Discussion started by: omsingh2k5
1 Replies

4. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

5. Solaris

Libraries required by commands

In solaris 10 how to I know what libraries are required by a particular command? please advise (1 Reply)
Discussion started by: Tirmazi
1 Replies

6. UNIX for Dummies Questions & Answers

validation required in unix

is there any way to check null data against some of the column in file My file have such structure 1,,4,SUMISHO ,SMG110880 ,1,12,SUMISHO CAPITAL MANAGEMENT (SINGAPORE) PTE LTD ,ACCT01,20080531,2008,5,30,20080630,1,1,TXGRP ,CGST ,1,74,5.18,74,0,5.18... (2 Replies)
Discussion started by: u263066
2 Replies

7. Shell Programming and Scripting

Help required to parse Oracle imp show=y output to DDL Commands

Hi, I generated an Oracle schema DDL script file using the show=y option of the Oracle import utility but the file that it generates needs a little more formating before we can run this as simple DDL comands to generate the schema at Target using the script file.Here is the simplified output of... (1 Reply)
Discussion started by: rajan_san
1 Replies

8. UNIX for Dummies Questions & Answers

Help required for these commands

Hi, I was going through some environment scripts where I require to make some changes. There are a couple of commands I cant understand at all. 1:- SIDS=${*:-} 2:- for element in detail.func common1.func status.func stop_start.func mc.global log.func under the for loop $element has been... (1 Reply)
Discussion started by: ayanbiswas
1 Replies

9. UNIX for Dummies Questions & Answers

Unix command help required

Hi All, Can anyone please help me in sort out the command to get the following command say File abc.log contains .... ...... This is the first line This is the second line This is the third line This is the fourth line This is the fifth line This is the first line This is the... (7 Replies)
Discussion started by: thaduka
7 Replies

10. UNIX for Dummies Questions & Answers

UNIX PATH info required PLEASE HELP (I'm new to unix)

I need to know how to enter a unix path in a cgi script for a guest book: example: My URL is http://www.kitachi.info I have an html file in the main folder on my site, the file is called : gbook.html what would the correct unix path for this file be ??? the part of the script... (1 Reply)
Discussion started by: akitachi
1 Replies
Login or Register to Ask a Question