Finding a format in a file and replacing it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a format in a file and replacing it
# 1  
Old 04-13-2012
Finding a format in a file and replacing it

Hi,

I need help in the following:
I have a file in directory with mutiple comma seperated values. One of the value is a date and time format like 2012-04-10 xx:yy:zz
I need to find that time format in the file and then replace it with xx:yy+1:zz
and then save it as a new file and copy it to a different directory.

How can I do this with shell scripting?
# 2  
Old 04-13-2012
Is it always in the same column? That would make it a lot easier.

IOW, show a sample of your input data, not just a single cell of it.
# 3  
Old 04-13-2012
yes most of the time.


Code:
test1,test2,T1,T2,2012-04-10 00:58:12,Sales,S,Test,70.00,76.21,16.2130,XX3546
test4,test7,T1,T4,2012-04-11 01:27:12,Sales,S,Test,10.00,16.21,6.2130,XY3546

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Scrutinizer; 04-14-2012 at 06:25 PM..
# 4  
Old 04-14-2012
Code:
gawk -F, '{gsub(/[^0-9]/, " ", $5);$5=strftime("%Y-%M-%d %H:%M:%S", mktime($5)+60)}1' OFS=, infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding the pattern and replacing the pattern inside the file

i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of value abc and ccc in the place of them. Input File: go to &abc=ddd; if... (16 Replies)
Discussion started by: saaisiva
16 Replies

2. Shell Programming and Scripting

Finding/replacing strings in some files based on a file

Hi, We have a file (e.g. a .csv file, but could be any other format), with 2 columns: the old value and the new value. We need to modify all the files within the current directory (including subdirectories), so find and replace the contents found in the first column within the file, with the... (9 Replies)
Discussion started by: Talkabout
9 Replies

3. Shell Programming and Scripting

Finding and replacing whole line using sed

Hi all, assume that i am having the following line in a file called file1. triumph and disaster must be treated same. I want to replace this line with. follow excellence success will chase you. is it possible to do this using sed. if possible kindly post me the... (2 Replies)
Discussion started by: anishkumarv
2 Replies

4. Homework & Coursework Questions

Finding/replacing text and redirection help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: What command would rename "sequentialInsert", in ~cs252/Assignments/commandsAsst/project/arrayops.h, to... (2 Replies)
Discussion started by: lothwen
2 Replies

5. Shell Programming and Scripting

Finding a String and Replacing it with an incremental value

Hi Friends, I have a text file which has about 200,000 records in it. we have a string which repeats in each and every record. So we have to write a script in ksh which finds that string on each line and replaces it with a new string(incremental value) for a set every four records. To be... (12 Replies)
Discussion started by: vpv0002
12 Replies

6. Shell Programming and Scripting

Finding and replacing links

Hi, I would like to do a scripting for finding the links based on the name I have and replace the links with the new name. General find command lists everything for that links ( means all the sub-sirs and all the files), i need only the main link and replace. Can you anyone give me some... (1 Reply)
Discussion started by: rrb2009
1 Replies

7. Shell Programming and Scripting

Need help in finding and replacing port numbers.

Hi All, I am trying to write a shell script which firstly will search some files and then increase the port numbers mentioned in them by a certain no. let me clear it with an example- suppose there r few files a,b,c,d.... file a's content- <serverEntries xmi:id="ServerEntry_1"... (3 Replies)
Discussion started by: ankushsingh10
3 Replies

8. Shell Programming and Scripting

help with finding & replacing pattern in a file

Hi everyone. Could u be so kind and help me with on "simple" shell script? 1. i need to search a file line by line for a pattern. example of a lines in that file 2947 domain = feD,id = 00 0A 02 48 17 1E 1D 39 DE 00 0E 00,Name Values:snNo = f10 Add AttFlag = 0 2. i need to find... (0 Replies)
Discussion started by: dusoo
0 Replies

9. Solaris

finding & replacing blank rows/spaces in a file

Can anyone help me find and replace blank rows in a file with a numeric value (ie blankrow=someTxtOrNumValue), the file is over 500,000 rows long so it would need to be the quickest way as I'll need to do this for multiple files...I would be greatfull for any suggestions....thanks sample file:... (2 Replies)
Discussion started by: Gerry405
2 Replies

10. UNIX for Dummies Questions & Answers

shellscript for finding and replacing in DG-UNIX

Newby here..... Is there any way of doing a find & replace within a huge file other than using something like : " vi - FileForReplacing < /u1/excel/consultants " contents of consultants file looks like :1,$s/0000031/CON/g :1,$s/0001032/JONES/g :1,$s/0001355/SMITH/g... (3 Replies)
Discussion started by: Gerry405
3 Replies
Login or Register to Ask a Question