awk/sed to search & replace data in first column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk/sed to search & replace data in first column
# 1  
Old 07-29-2011
awk/sed to search & replace data in first column

Hi All,

I need help in manipulating the data in first column in a file.

The sample data looks like below,

Code:
Mon Jul 18 00:32:52 EDT 2011,NULL,UAT
Jul 19 2011,NULL,UAT

1] All field in the file are separated by ","
2] File is having weekly data extracted from database
3] For eg. Consider week from Jul 18 2011 To Jul 24 2011

Here I would like to search for date pattern as "Jul 18", "Jul 19","Jul 20" so on & replace it with "Jul 18 2011" type pattern.

Could you pls help me.

Thanks.
# 2  
Old 07-29-2011
The source file format is strange.

in your sample, there are two different dates displayed.

Mon Jul 18 00:32:52 EDT 2011
Jul 19 2011
# 3  
Old 07-29-2011
I think Mon Jul 18 00:32:52 EDT 2011,NULL,UAT is input and the other line is output.

But anyway do you have GNU date? And what system do you use if you not?
# 4  
Old 07-29-2011
Yes, I have these 2 date patterns in my input file & wanted to convert it to "Jul 18 2011" pattern.

I am using Solaris 8.
# 5  
Old 07-29-2011
Ok, you do not have GNU date and you have two patterns in your input file. You want that there is only one pattern.

Mon Jul 18 00:32:52 EDT 2011,NULL,UAT # changes to Jul 18 2011,NULL,UAT
Jul 19 2011,NULL,UAT # not changes

Yes?

---------- Post updated at 11:53 AM ---------- Previous update was at 11:49 AM ----------

You don't need and date command if I'm right about pattern but it's just a habit (maybe bad one) to ask about it any time when I see questions about date manipulations.
# 6  
Old 07-29-2011
yazu ... Yes, your understanding is very right, please help.
# 7  
Old 07-29-2011
Try:
Code:
sed 's/^\(...\) \(...\) \([0-9][0-9]\).*2011/\2 \3 2011/' INPUTFILE

It works only for 2011 year but it's easy enough to fix this.

PS And you should'n have other "2011" in your strings.
This User Gave Thanks to yazu For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk search and replace nth column by using a variable.

I am passing a variable and replace nth value with the variable. I tried using many options in awk command but unable to ignore the special characters in the output and also unable to pass the actual value. Input : "1","2","3" Output : "1","1000","3" TempVal=`echo 1000` Cat... (2 Replies)
Discussion started by: onesuri
2 Replies

2. Shell Programming and Scripting

How to search and replace string in column in file with command sed?

how to search and replace string in column in file with command sed or other search "INC0000003.in" and replace column 4 = "W" $ cat file.txt INC0000001.in|20150120|Y|N|N INC0000002.in|20150120|Y|N|N INC0000003.in|20150120|Y|N|N INC0000004.in|20150120|Y|N|Noutput... (4 Replies)
Discussion started by: ppmanja3
4 Replies

3. Shell Programming and Scripting

awk to search for specific line and replace nth column

I need to be able to search for a string in the first column and if that string exists than replace the nth column with "-9.99". AW12000012012 2.38 1.51 3.01 1.66 0.90 0.91 1.22 0.82 0.57 1.67 2.31 3.63 0.00 AW12000012013 1.52 0.90 1.20 1.34 1.21 0.67 ... (14 Replies)
Discussion started by: ncwxpanther
14 Replies

4. Shell Programming and Scripting

Search & Replace content of files using gsub in awk

Hi,I have 2 files master.txt & reference.txt as shown below & i require o/p as mentioned in file 3 using awk but content is not replacing properlymaster.txt:... (15 Replies)
Discussion started by: siramitsharma
15 Replies

5. Shell Programming and Scripting

Search & replace content using awk/gsub

Hi, I have two files master.txt & reference.txt. Sample below Master.txt 2372,MTS,AP 919848001104,Airtel,DL 0819,MTS,MUM 919849788001,Airtel,AP 1430,Aircel MP,20 Reference.txt 2372,919848701430,46467 919848002372,2372,47195 2372,919849788001,59027 0819,028803,1 0819,029801,1... (2 Replies)
Discussion started by: siramitsharma
2 Replies

6. Shell Programming and Scripting

Using sed to search and replace data

Hi, Kindly need your expertise in this problem. I have to search and replace data. The problem is, the data is in the same format but slightly different content. What I need is sed commands that can work for those "slightly different content". input: ... (3 Replies)
Discussion started by: Alvin123
3 Replies

7. Shell Programming and Scripting

awk/sed string search and replace

Need help with either sed or awk to acheive the following file1 ----- In the amazon forest The bats eat all the time... mon tue wed they would eat berries In the tropical forest The bats eat all the time... on wed bats eat nuts In the rain forest The bats eat all the time... on... (2 Replies)
Discussion started by: jville
2 Replies

8. Shell Programming and Scripting

Help with sed search&replace between two strings

Hi, i read couple of threads here on forum, and googled about what bugs me, yet i still can't find solution. Problem is below. I need to change this string (with sed if it is possible): This is message text that is being quoted to look like this: This is message text that is being quotedI... (2 Replies)
Discussion started by: angrybb
2 Replies

9. Shell Programming and Scripting

awk/sed column replace using column header - help

$ cat log.txt Name Age Sex Lcation nfld alias xsd CC 25 M XYZ asx KK Y BB 21 F XAS awe SS N SD 21 M AQW rty SD A How can I replace the column with header "Lcation" with the column with header "alias" and delete the "alias" column? so that the final output will become: Name Age Sex... (10 Replies)
Discussion started by: jkl_jkl
10 Replies

10. Shell Programming and Scripting

Help, sed search&replace

Plzzzz, tell me some script about this... What does this mean ? sed '/^ */s///' sed '/^/s// /' and why it's diferent ??? sed '/ */s// /g' and sed 's/ */ /g'. It's all the same ??? Thanks you very much (2 Replies)
Discussion started by: mle
2 Replies
Login or Register to Ask a Question