how to extract a substring froma file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to extract a substring froma file
# 1  
Old 01-23-2008
Question how to extract a substring from a file

hi all, I'm really newbie on this and I need some help.
how is the best way to extract a strig or substring from a each line in a file.

e.g. I want to print only this ERROR=JUD+the followed numbers from one line like this one, considering the numbers change related to different errors

.....bla+|ERRORDESC=JUD049+The+dimension+is+invalid+Failed+to+find+a+dimension+value+for+endeca+navi gation+parameter+%3A+Endec
aNavigationParameter+%3A+%5B+EndecaDimension+-+%27Holiday+Type%27+%28id%3D0%29+%5D%2C+%5B+Dimension+Node+%3A+name+%3D+City+Break%2C+id+%3D+0%2C+sr c+%3D+null+
%5D|ERROR=JUD049|sourceRUID=bla......

considering the line is much longer I just paste part of it.
maybe with SED or awk can help any guru?
thanks
# 2  
Old 01-23-2008
Lightbulb

go it

sed -n 's/.*\(ERROR=JUD...\).*/\1/p' <file>

thanks Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract a substring from a file

Hello, A question please. A have a file that contains a string. Ex: AAAABBCCCCCDDEEEEEEEEEEFF I'd want to recover 2 substrings, 'BB' and 'FF' and then leave them in a new file. From position 5, 2 caracters (ex:"BB") and from position 25, 2 caracters (ex:"FF") in a file. Could anoyone help me... (3 Replies)
Discussion started by: nolo41
3 Replies

2. Shell Programming and Scripting

Extract substring in a file

Hello, A question please. A have a file that contains a string. Ex: AAAABBCCCCCDDEEEEEEEEEEFF I'd want to recover 2 substrings, 'BB' and 'FF' and then leave them in a new file. Could anoyone help me please? Thanks in advance (3 Replies)
Discussion started by: nolo41
3 Replies

3. Shell Programming and Scripting

Extract values froma line in file

p.txt T|DCNT=100|RECCHK=22222.2|PERCHK=32323|# I want to extract the value of 100 22222.2 and 32323 and assign it to variable x1,y1,z1 x=`cut -f2 -d "=" p.txt` x1=`echo $x | cut -f1 -d "|" ` y=`cut -f3 -d "=" p.txt` y1=`echo $y | cut -f1 -d "|" ` z=`cut -f4 -d "=" p.txt` z1=`echo $z... (3 Replies)
Discussion started by: w020637
3 Replies

4. Shell Programming and Scripting

Extract substring specif position and length from file line

Hi gurus, I am trying to figure out how to extract substring from file line (all lines in file), as specified position and specified legth. Example input (file lines) dhaskjdsa dsadhkjsa dhsakjdsad hsadkjh dsahjdksahdsad sahkjd sahdkjsahd sajkdh adhjsak I want to extract substring on... (5 Replies)
Discussion started by: ProsteJa
5 Replies

5. Solaris

Extract substring from a string

i have srtring i.e. "NAME,CLASS,AGE" (length of string is not constant) and from this string i've extract each word delimited by "," (comma). INPUT: "NAME,CLASS,AGE" OUTPUT: NAME CLASS AGE how can i do that? i have tried some string manipulation function like... (5 Replies)
Discussion started by: jadoo_c2
5 Replies

6. Shell Programming and Scripting

Remove a non-specific word froma file

Hi All, I am encountering a problem while removing a string from a file. Actually, i have done this thing before using sed to replace the word but this time word is not specfic. its value is changing with each file. e.g. %HD% Serial Number list per DN required. +3... (2 Replies)
Discussion started by: apjneeraj
2 Replies

7. UNIX for Dummies Questions & Answers

Print values of a string froma file

Hi, I have a problem in getting values of a specific string on a file, can you please help me what command or script that I will use to get it? I have a file with the following sample contents. I need to print the values of time. The time sometimes appears on column 2 or column 3. Please... (2 Replies)
Discussion started by: ayhanne
2 Replies

8. Shell Programming and Scripting

Extract a substring.

I have a shell script that uses wget to grab a bunch of html from a url. URL_DATA=`wget -qO - "$URL1"` I now have a string $URL_DATA that I need to pull a substring out of..say I had the following in my string <p><a href="/scooby/929011567.html">Dog pictures check them out! -</a><font... (3 Replies)
Discussion started by: shellpower
3 Replies

9. Shell Programming and Scripting

Need Help... to extract the substring

> tnsping $TWO_TASK | grep HOST Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.12.10.212)(PORT = 1540)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = OMTST15))) I want to extract like this HOST = 10.12.10.212 PORT = 1540 SERVICE_NAME = OMTST15 I... (4 Replies)
Discussion started by: dashok.83
4 Replies

10. Shell Programming and Scripting

Sed extract substring on (OS X)

On OS 10.4.11 I have filenames like: 670711 SA T2 v1-1_DS_EF.doc CT_670520 AM T1 v1-2_DS_EF.doc CT_670716 - 2 SA T4 v1-2_DS_EF.doc CT_670713 SA T3 v1-1_DS_EF.doc 670421 PA DYP1 v1-1_DS_EF.doc CT_670425 PA DYP2 v1-1_DS_EF.doc CT_670107 RA T3 v1-2_DS_EF.doc CT_670521 AM T2 v1-2_DS_EF.doc... (3 Replies)
Discussion started by: mlommel
3 Replies
Login or Register to Ask a Question