Problems with delimiters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems with delimiters
# 1  
Old 07-10-2008
Problems with delimiters

Hello,

I have data in a file something like this -

UNB+UNOA:1+006415160:1+AR0000012360:ZZ+080701:0552+2++DELFOR++++T'UNH+2+DELFORSmilie:97A:UN

Here, the delimiters used are + , : and ' . I have a set of such files in which these delimiters vary from one file to another.

I am developing a shell script which needs to take certain values from fields in this file depending on their positions which I will be doing it with the help of cut command.

My problem is how to find these varying delimiters from file to file. Means, in every file , how can i find out what is the delimiter after UNB(here +) , after UNOA (here Smilie or before UNH (here '). I will store them in variables & then search for my required fields.

Please help me. It is very urgent.
# 2  
Old 07-10-2008
Question what if just change all the delimiters to one character?

Is there a reason for some many different delimiters? Why not change the + to | then the : to | then the ' to | ? Then, your file would be consistent.

Code:
> echo $inp
UNB+UNOA:1+006415160:1+AR0000012360:ZZ+080701:0552+2++DELFOR++++T'UNH+2+DELFOR:97A:UN
> echo $inp | tr "+" "|" | tr ":" "|" | tr "'" "|"
UNB|UNOA|1|006415160|1|AR0000012360|ZZ|080701|0552|2||DELFOR||||T|UNH|2|DELFOR|97A|UN


Last edited by joeyg; 07-10-2008 at 01:04 PM.. Reason: added sample unix code
# 3  
Old 07-10-2008
Exactly. Create a "filter". Make all delimiters consistent (1 delimiter) then use that output to do your cuts, etc.

InputWithManyDelimiters | filterScript | cut -fn -d "~" where "~" is what ever delimiter you choose as the cannoical one.... "~" (tilde) is a good one at least for English because the character is not commonly used in data...
# 4  
Old 07-10-2008
.... or specify multiple delimeters/FieldSeparators with 'awk'
# 5  
Old 07-10-2008
Quote:
Originally Posted by joeyg
... Why not change the + to | then the : to | then the ' to | ? Then, your file would be consistent.

Code:
> ...
> echo $inp | tr "+" "|" | tr ":" "|" | tr "'" "|"

Useless Use Of tr Smilie
Code:
> echo $inp | tr ":|+|'" "|"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut between two delimiters, / and .

BASH : I have a very long list I am parsing through: 10/10/19... (5 Replies)
Discussion started by: jeffs42885
5 Replies

2. Shell Programming and Scripting

Delimiters with awk?

I have a file which is separated by delimiter "|", but the prob is one of my column do contain delimiter as description so how can i differentiate it? PS : the delmiter does have backslash coming before it, if occurring in column Annual|Beleagured|Desc|Denver... (2 Replies)
Discussion started by: nikhil jain
2 Replies

3. Shell Programming and Scripting

Inserting Delimiters

Hi Team, I am trying to get the data in below format Jan 01 | 19:00:32 | xyz | abc | sometext | string however I am not sure of the total number strings which can come in the record hence i cant use something like below as it can end $6 or it can go further cat file| awk... (8 Replies)
Discussion started by: rakesh_411
8 Replies

4. Shell Programming and Scripting

sort with different delimiters

I have a file with the following lines in it: Inbound1:remote - - 01/Nov/2011:08:29:51 -0500 "GET / HTTP/1.1" 404 2098 HTTP Inbound1:remote - - 02/Dec/2011:08:31:42 -0500 "GET / HTTP/1.1" 404 2098 HTTP Inbound3:remote - - 01/Oct/2011:08:29:52 -0500 "GET / HTTP/1.1" 404 2098 HTTP Inbound4:remote... (5 Replies)
Discussion started by: oldman2
5 Replies

5. Shell Programming and Scripting

Use two delimiters in awk

I have a file having lines like: 14: <a="b" val="c"/> 18: <a="x" val="d"/> 54: <a="b" val="c"/> 58: <a="x" val="e"/> I need to create a file with output: 14 d 54 e So basically, for every odd line I need 1st word if delimiter is ':' and for every even... (14 Replies)
Discussion started by: shekhar2010us
14 Replies

6. Shell Programming and Scripting

Delimiters in awk

Line from input file a : b : c " d " e " f : g : h " i " j " k " l output k b a Its taking 7th word when " is the delimiter, 2nd and 1st word when : is the delimiter and returning all in one line.... I am on solaris Thanks..... (1 Reply)
Discussion started by: shekhar2010us
1 Replies

7. Shell Programming and Scripting

Split using two delimiters

I'm trying to do a split using two delimiters. The first delimiter is ": " (or we could call it :\s). The second is "\n". How can or these delimiters so I can toss the values into an array without issue? I tried @array = split /:\s|\n/, $myvar; This doesn't seem to be working. Any an... (3 Replies)
Discussion started by: mrwatkin
3 Replies

8. Shell Programming and Scripting

Two delimiters with AWK

Hello, this thread is more about scripting style than a specific issue. I've to grep from a output some lines and from them obtain a specific entry delimited by < and >. This is my way : 1) grep -i user list | awk '{FS="<";print $NF}' | sed -e 's/>//g' 2) grep -i user list | cut -d","... (10 Replies)
Discussion started by: gogol_bordello
10 Replies

9. Solaris

To extract everything between two delimiters

My input file looks like " @$SCRIPT/atp_asrmt_adj.sql $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1005w.pls $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1006w.pls start $SCRIPT/cim1020d.sql;^M spool $DATA/cim1021m.sql @$DATA/cim1021m.sql ! rm $DATA/cim1021m.sql spool $DATA/cim1021m.sql... (1 Reply)
Discussion started by: dowsed4u8
1 Replies

10. Shell Programming and Scripting

Delimiters missing

Hi I have a pipe-delimited file where I eventually need to replace a string stored on the 3th field on a specific record. This is how the file looks like: A|Mike|Lvl 1|... B|... A|Maria|Lvl 1|... C|... B|... A|Jimmy|Lvl 2|... C|... A|Carry|Lvl 0|... C|... B|... A|John|Lvl 8|...... (2 Replies)
Discussion started by: Indalecio
2 Replies
Login or Register to Ask a Question