Attaching an end delimeter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Attaching an end delimeter
# 1  
Old 09-29-2011
Attaching an end delimeter

Hi,
I have a file below
I want to attach an end delimeter '{}' after the time stamp


input file
Code:
22113350444356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660PM
22113350398356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660AM
22113350621356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660PM
22113335524356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660AM

output file
Code:
22113350444356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660PM{}
22113350398356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660AM{}
22113350621356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660PM{}
22113335524356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660AM{}

I have tried the below
Code:
perl -i -ne 's;[A,P]M\n;$1{}\n;g;print;' inputfile

which obviously not working.. can anyone please help me

Last edited by ratheeshjulk; 09-29-2011 at 08:01 AM.. Reason: file name in the code changed
# 2  
Old 09-29-2011
Code:
perl -i -pe's/:\d{3}\w{2}$/$&\{\}/' infile

This User Gave Thanks to radoulov For This Post:
# 3  
Old 09-29-2011
Thanks..
Can you please explain what the code does..
# 4  
Old 09-29-2011
Code:
$ perl -lane 'if($_ =~ /[AP]M$/){print $_ . "\{\}";}else{print $_}' infile
22113350444356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660PM{}
22113350398356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660AM{}
22113350621356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660PM{}
22113335524356|Status:Assigned,Notes:
APP PRD |Sep 28 2011 12:12:55:660AM{}

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 09-29-2011
using nawk ..
Code:
$ nawk '{if(NR%=2) {print $0} else {print $0"{}"}}' infile

# 6  
Old 09-29-2011
Quote:
Originally Posted by ratheeshjulk
Thanks..
Can you please explain what the code does..
Yes,
it appends {} to the lines ending by a semicolon, 3 digits and 2 word characters:

Code:
\d{3} - 3 digits
\w{2} - 2 word characters
$ - end of line

This User Gave Thanks to radoulov For This Post:
# 7  
Old 09-30-2011
Through Sed..
Code:
sed '/:$/!s/$/{}/' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Problem in attaching zone

Hi, I have installed few Veritas packages in my local zone. Prior to that, I had detached non-global zones. After successfull installation of veritas packages on global zone, I am attaching non-global zones with -u option, but stuck with one NGZ. One of the NGZ is having gsk7bas 7.0.4.38 while... (5 Replies)
Discussion started by: solaris_1977
5 Replies

2. Shell Programming and Scripting

Replacing the delimeter with other delimeter

Hi Friends, I have a file1.txt as below 29123973Ç2012-0529Ç35310124Ç000000000004762Ç00010Ç20Ç390ÇÇÇÇF 29123974Ç20120529Ç35310125Ç0000000000046770Ç00010Ç20Ç390ÇÇÇÇF 29123975Ç20120529Ç35310126Ç0000000000046804Ç00010Ç20Ç390ÇÇÇÇF 29123976Ç20120529Ç35310127Ç0000000000044820Ç00010Ç20Ç390ÇÇÇÇF i have a file2.txt... (4 Replies)
Discussion started by: i150371485
4 Replies

3. Solaris

Help with attaching mirrors

Hi Guys, I need a help with attaching the sub mirrors as it keep throwing errors. I have done solaris live upgrade and it was succesful but it keeps throwing error only for root (s0) and swap (s1)when i try to attach them. For rest of the partitions for slices 3,4,5 on target 1 are able to... (4 Replies)
Discussion started by: phanidhar6039
4 Replies

4. Shell Programming and Scripting

Help in attaching the csv sheet in alerts

Hi Experts, An automation of Unprocessed data(oracle rows) table where a shell script is written to check if there are any records inserted into the table on daily basis. Whenever rows passed into this table on a particular day, there will be a time where the script can be scheduled around 7:00 am... (2 Replies)
Discussion started by: defendersubbu
2 Replies

5. Solaris

Veritas not attaching replaced disk

Hi, I`m on SunFire480R with Solaris 10. Disk in rootdg group failed, so it was replaced. However, I cannot make Veritas initalise the replaced disk: # vxdctl enable # vxdisk list c1t0d0s2 Device: c1t0d0s2 devicetag: c1t0d0 type: auto flags: online error private autoconfig... (1 Reply)
Discussion started by: masloff
1 Replies

6. Shell Programming and Scripting

Count the delimeter from a file and delete the row if delimeter count doesnt match.

I have a file containing about 5 million rows, in the file there are some records which has extra delimiter at random position. (we dont know the positions), now we have to Count the delimeter from each row and if the count of delimeter is not matching then I want to delete those rows from the... (5 Replies)
Discussion started by: Akumar1
5 Replies

7. Shell Programming and Scripting

Attaching a logfile to the Script

Hello guys. I've recently written a basic utilities script just for home use. and i want to attach a logfile to it that will record all the commands that where executed in that script. Then just so i can add the d%b%y% and make each logfile unique and i can look back in each logfile to see what i... (9 Replies)
Discussion started by: matt02
9 Replies

8. Shell Programming and Scripting

attaching the file to mail

Hi, In my script, i am using tar to combine 2 files, so that i can attach it to the mail. everything is working fine and sending the mail successfully. But, when i save the file to desktop and unzip it. a series of directories are there and finally those tar files are there. i am using tar -cf... (1 Reply)
Discussion started by: javeed7
1 Replies

9. Shell Programming and Scripting

Add Delimeter,

I want to add the delimiter in particular positions in one txt file. My file is : 123450000000000testing 898983920202020testfil . . . 1-5 -- after 5th position add , 6-10 -- after 10th position add , 11-7 -- like wise.. Expecting output is: 12345,0000000000,testing... (5 Replies)
Discussion started by: Jairaj
5 Replies

10. Shell Programming and Scripting

Delimeter used in data

Blasted data inputters :mad: they always have to screw my data up....My comma delimited file with three fields ( firstname,surname and address ) has been screwed up by people entering addresses like this (putting a comma in between the house number and the street name) 142,Stonewall Avenue ... (8 Replies)
Discussion started by: hcclnoodles
8 Replies
Login or Register to Ask a Question