Need help to extract a string delimited by any special character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to extract a string delimited by any special character
# 8  
Old 06-01-2005
Thanks Vino for your help

My input file is as below

ISA~00~ ~00~ ~ZZ~12345 ~ZZ~54321 GS~SH~12345 ~54321
ST~86~000000007
BSN~00~0958
DTM~011~ET

And, when I ran the code above, the below results appeared

ISA~00~ ~00~ ~ZZ~12345 ~ZZ~54321 GS~SH~12345 ~54321
ST~86~000000007
BSN~00~0958
DTM~011~ET


My requirement is to get the first 2 or 3 characters like ISA, GS, ST, BSN and DTM. In this file, the special character is '~', but in other files it may vary.

Thanks,
AK
# 9  
Old 06-01-2005
What shell and os are you using ?

Vino
# 10  
Old 06-01-2005
This is what I got on my terminal
Code:
[~/temp]$ awk -F"[*~+]" '{print $1}' kum.txt 
ISA
ST
BSN
DTM

where kum.txt is

Code:
[~/temp]$ cat kum.txt 
ISA~00~ ~00~ ~ZZ~12345 ~ZZ~54321 GS~SH~12345 ~54321
ST~86~000000007
BSN~00~0958
DTM~011~ET

Vino
# 11  
Old 06-01-2005
Hi Vino,

I am using SUN OS 5.8, and Korn Shell.

I am not getting the desired results.
# 12  
Old 06-01-2005
Dont have any SunOS distro at my disposal. Smilie

Someone could please check it out.

Vino
# 13  
Old 06-01-2005
Quote:
Originally Posted by kumariak
there is a special character like *, ~ or + etc
whoa - the reason you're not getting the desired output is because you're not giving us the desired input Smilie

We'll need to know *all* the delimeters used, we can't make them up.

Cheers
ZB
# 14  
Old 06-01-2005
Hi,

Vino is getting the desired output on his os and shell.

I can use the delimiters like * ~ + : <

Can anyone help??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract string between two special chracters

Hi Folks - I'm trying to extract the string between two special characters, the "-" and "." symbols. The string format is as such: _PBCS_URL_PRD=https://plan-a503777.pbcs.us6.ocloud.com _PBCS_URL_TST=https://pln-test-a503777.pbcs.us6.ocloud.comIn the above case, I need to extract "a503777".... (7 Replies)
Discussion started by: SIMMS7400
7 Replies

2. Shell Programming and Scripting

Perl split string separated by special character

Hello I have string (string can have more sections) LINE="AA;BB;CC;DD;EE"I would like to assigne each part of string separated by ";" to some new variable. Can someone help? (4 Replies)
Discussion started by: vikus
4 Replies

3. UNIX for Dummies Questions & Answers

Extract string between two special characters

Hi, I have a file that looks something like >1-18*anc... (12 Replies)
Discussion started by: jyu429
12 Replies

4. Shell Programming and Scripting

Extract string between 2 special characters

Hi, I have a unix file with contents as below Line1: ABC MNN X$$QWERTY$$ JKL Line2: HELLO $$HOW$$ ARE $$YOU$$ DOING i want to extract the string between $$ and $$ ie i want the output as QWERTY HOW YOU i want those strings seperated by some character say | desired output is... (7 Replies)
Discussion started by: vinredmac
7 Replies

5. Shell Programming and Scripting

How to replace with a special character in String

Hi, I am beginner to Shell Scripting. I have a String like this "testabcdef", i need the first character as it is and the remaining character should be replaced by the the '*' character. e.g(t***********) PLZ Suggest me. (5 Replies)
Discussion started by: nanthagopal
5 Replies

6. Shell Programming and Scripting

Extract character from string

ps -eaf | grep “oracleTRLV (LOCAL=NO)” | while read ora_proc do echo $ora_proc done I would like to modify the above shell so that if character 13 and 14 equal "12" to do something. Sorry I'm new to shell:( (14 Replies)
Discussion started by: NicoMan
14 Replies

7. Shell Programming and Scripting

Delete parts of a string of character in one given column of a tab delimited file

I would like to remove characters from column 7 so that from an input file looking like this: >HWI-EAS422_12:4:1:69:89 GGTTTAAATATTGCACAAAAGGTATAGAGCGT U0 1 0 0 ref_chr8.fa 6527777 F DD I get something like that in an output file: ... (13 Replies)
Discussion started by: matlavmac
13 Replies

8. Shell Programming and Scripting

Remove box like special character from end of string

Hi All, How to remove a box like special character which appears at the end of a string/line/record. I have no clue what this box like special character is. It is transparent square like box. This appears in a .DAT file at the end of header. I'm to compare a value in header with a parameter.... (16 Replies)
Discussion started by: Qwerty123
16 Replies

9. Shell Programming and Scripting

Perl Script Syntax to Extract Everything After Special Character

Hi, I am writing a Perl script that reads in many lines, if a line meets the criteria I want to edit, it. For example, the script will return the following example line... test=abc123 All I want to do is strip off the "test=" and just be left with the abc123. In my script I can easily... (3 Replies)
Discussion started by: edrichard
3 Replies

10. Shell Programming and Scripting

replacing string with special character ???

the problem is while replacing the old string with new one with the help of SED i am unable to replace the special characters with new strings. how can i do that? i dont want the user to be given the trouble to write '\' before every special characters like * , . , \ , $ , &. sed... (4 Replies)
Discussion started by: imppayel
4 Replies
Login or Register to Ask a Question