Substring between third and fourth occurrence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substring between third and fourth occurrence
# 1  
Old 06-25-2011
Substring between third and fourth occurrence

Hi ,

Please help me to get the data extracted between the 3rd and 4th dot of a transaction file.

Code:
 
Source data
TRANS,ARRIVED,ABC.1Gt.CDRFLOW123.MAINFRAMES.SYS.tXT/ARRIVED,TRANS/CDRFLOW123.MAINFRAMES.SYS.tXT/ARRIVED,TRANS 
TRANS,DELIVERED,ABC.1Gt.CDRFLOW123.MAINFRAMES.SYS.tXT/DELIVERED,TRANS/CDRFLOW123.MAINFRAMES.SYS.tXT/DELIVERED,TRANS

Code:
 
TargetData
TRANS,ARRIVED,ABC.1Gt.CDRFLOW123.MAINFRAMES.SYS.tXT/MAINFRAMES_ARRIVED,TRANS/CDRFLOW123.MAINFRAMES.SYS.tXT/MAINFRAMES_ARRIVED,TRANS 
TRANS,DELIVERED,ABC.1Gt.CDRFLOW123.MAINFRAMES.SYS.tXT/MAINFRAMES_DELIVERED,TRANS/CDRFLOW123.MAINFRAMES.SYS.tXT/MAINFRAMES_DELIVERED,TRANS

I am trying to extract the data between 3rd and 4th dot ABC.1Gt.CDRFLOW123.MAINFRAMES.SYS.tXT and I need to place the extracted data in the same column after the '/' charcter.

I didtn't try any code as of now, I am searching this forum for some awk scripts to do the same.

Thx,wangkc
# 2  
Old 06-25-2011
Hi
Not clear with your question. You said between 3rd and 4th dot, which is application to the third field(assuming , as delimiter). However, for the 4th field, I assumed it to be between 1st and 2nd dot:


Code:
$ cat a
TRANS,ARRIVED,ABC.1Gt.CDRFLOW123.MAINFRAMES.SYS.tXT/ARRIVED,TRANS/CDRFLOW123.MAINFRAMES.SYS.tXT/ARRIVED,TRANS
TRANS,DELIVERED,ABC.1Gt.CDRFLOW123.MAINFRAMES.SYS.tXT/DELIVERED,TRANS/CDRFLOW123.MAINFRAMES.SYS.tXT/DELIVERED,TRANS


$ awk '{split($3,a,/\./);split($3,b,/\//);$3=b[1]"/"a[4]"_"b[2];split($3,a,/\./);split($4,a,/\./);split($4,b,/\//);$4=b[1]"/"b[2]"/"a[2]"_"b[3];}1' FS=, OFS=, a
TRANS,ARRIVED,ABC.1Gt.CDRFLOW123.MAINFRAMES.SYS.tXT/MAINFRAMES_ARRIVED,TRANS/CDRFLOW123.MAINFRAMES.SYS.tXT/MAINFRAMES_ARRIVED,TRANS
TRANS,DELIVERED,ABC.1Gt.CDRFLOW123.MAINFRAMES.SYS.tXT/MAINFRAMES_DELIVERED,TRANS/CDRFLOW123.MAINFRAMES.SYS.tXT/MAINFRAMES_DELIVERED,TRANS

$


Guru.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed print from last occurrence match until the end of last occurrence match

Hi, i have file file.txt with data like: START 03:11:30 a 03:11:40 b END START 03:13:30 eee 03:13:35 fff END jjjjjjjjjjjjjjjjjjjjj START 03:14:30 eee 03:15:30 fff END ggggggggggg iiiiiiiiiiiiiiiiiiiiiiiii I want the below output START (13 Replies)
Discussion started by: Jyotshna
13 Replies

2. Shell Programming and Scripting

Substitute first occurrence of keyword if occurrence between two other keywords

Assume a string that contains one or multiple occurrences of three different keywords (abbreviated as "kw"). I would like to replace kw2 with some other string, say "qux". Specifically, I would like to replace that occurrence of kw2 that is the first one that is preceded by kw1 somewhere in the... (4 Replies)
Discussion started by: M Gruenstaeudl
4 Replies

3. Shell Programming and Scripting

Bash subtract fourth octet of an IP by 1

Hello, Im looking to help out my team by automating a simple search list. The user will look for a peering ip /30. For example 192.168.1.2/30 and gets the result. Im trying to get the entered /30 and subtract the last octet by one. echo -n "Enter peering ip : "; read peeringip cat... (3 Replies)
Discussion started by: D'go
3 Replies

4. UNIX for Dummies Questions & Answers

How to find second and fourth Monday of the month?

Hi, I have came across the scenario where, we have to run the script on second and fourth Monday of each month. I have tried to search man page of date and also forum for it but, could not get any answer to this. Can you please advise how can we get second and fourth Monday of the month? ... (18 Replies)
Discussion started by: Prathmesh
18 Replies

5. Shell Programming and Scripting

replace by match on fourth column

Hi friends, My input file is this way chr1 100 200 "abc" chr1 350 400 "abc" chr2 450 600 "def" chr2 612 780 "def" How do I make this file into chr1 100 400 "abc" chr2 450 780 "def" This is basically matching on the fourth column and taking the minimum of second column and the... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

6. Shell Programming and Scripting

How can I delete every third AND fourth line in a file?

cat test.nmea|awk 'NR%3!=0' This deletes the 3rd line, or I can delete the fourth but I can't figure out how to delete the 3rd and 4th together. I'm looking for a quick way to make a GPS log half its size. Also how do I pipe the output to another file? Hope someone can help! (5 Replies)
Discussion started by: traveltrousers
5 Replies

7. Shell Programming and Scripting

Use awk to have the fourth column with spaces

Hi Gurus, We have a ftpserver from which we do a dir command and output it to a local file. The content of the ftpfile is: 07-15-09 06:06AM 5466 ABC_123_ER19057320090714082723.ZIP 07-15-09 06:07AM 3801 ABC_123_ER19155920090714082842.ZIP 07-15-09 06:07AM ... (14 Replies)
Discussion started by: donisback
14 Replies

8. Shell Programming and Scripting

fourth field is number in a line

hi i hav a file like 121212 asdd d 7 dfsdffdffsdfsdfsdfdf rrretrtrtre 121212 asdd d 5 dfsdffdffsdfsdfsdfdf rrretrtrtre 121212 asdd d 5 dfsdffdffsdfsdfsdfdf rrretrtrtre 121212 asdd d 4 dfsdffdffsdfsdfsdfdf rrretrtrtre 121212 asdd d 6 dfsdffdffsdfsdfsdfdf rrretrtrtre i need to... (4 Replies)
Discussion started by: Satyak
4 Replies
Login or Register to Ask a Question