Print the string between spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print the string between spaces
# 1  
Old 12-02-2010
Print the string between spaces

How to print the strings within a line between two spaces .

Code:
<ns1:providerErrorCode>141</ns1:providerErrorCode> <ns1:providerErrorText>business_rule_exception-Server.404:Cannot proceed because the subscriber with phone number [] is either suspended or the account has an unpaid balance.</ns1:providerErrorText> <ns1:errorSystem>O56</ns1:errorSystem><ns1:errorTransactionId/><ns1:errorProgramId>ManageServices</ns1:errorProgramId>

There are spaces before and after the providerErrorText. Please let me know how to print only this from a line.
# 2  
Old 12-02-2010
Code:
perl -nle '/(?<= ).*(?= )/;print $&' file

# 3  
Old 12-02-2010
Code:
awk -F' [<>]' '{print $2}' file

Precise match, not using the spaces as markers:
Code:
grep -Eo "<(ns1:providerErrorText)>.*</\1>" file

# 4  
Old 02-24-2011
Sorry for delayed response. But all the above command is not providing the right output. I just needed the only the line between the two spaces.
# 5  
Old 02-24-2011
If you are looking for the line in blue then all of the commands above should give you this. If not, what are you getting and what output are you looking for?
# 6  
Old 02-24-2011
perl -nle '/(?<= ).*(?= )/;print $&' sample.txt [Partial Output]

<OUTPUT>

<kjdjkn><jnsdnsdknsd>jnsdkjns<kjnsdkjndsj><kjnsdjnsdkj>987329<ksdnsdkjn><detail><ns1:errorDetailIt em xmlns:ns1="http://integration.xyz.com/common/ErrorD.xsd"><ns1SmilieroviderError><ns1SmilieroviderErrorCode>100</ns1SmilieroviderErrorCode> <ns1SmilieroviderErrorText>com.Resource-Exists-Exception : permission already exists</ns1SmilieroviderErrorText>

</OUTPUT>

awk -F' [<>]' '{print $2}' sample.txt [Displaying Begining of the Line]

<OUTPUT>

05:22:58,434<REQUEST><soapenv:Envelope
14:30:58,966<REQUEST><soapenv:Envelope
01:09:36,981<REQUEST><soapenv:Envelope
10:41:43,842<REQUEST><soapenv:Envelope
11:41:20,957<REQUEST><soapenv:Envelope
12:22:19,059<REQUEST><soapenv:Envelope
12:26:45,606<REQUEST><soapenv:Envelope
23:52:15,848<REQUEST><soapenv:Envelope
11:05:18,754<REQUEST><soapenv:Envelope
11:37:27,279<REQUEST><soapenv:Envelope
15:45:37,480<REQUEST><soapenv:Envelope
10:32:00,711<REQUEST><soapenv:Envelope
10:32:13,459<REQUEST><soapenv:Envelope
11:52:51,915<REQUEST><soapenv:Envelope
11:58:40,728<REQUEST><soapenv:Envelope
14:21:15,353<REQUEST><soapenv:Envelope
19:45:25,138<REQUEST><soapenv:Envelope
02:06:09,454<REQUEST><soapenv:Envelope
15:35:48,146<REQUEST><soapenv:Envelope
16:43:03,078<REQUEST><soapenv:Envelope
16:47:11,092<REQUEST><soapenv:Envelope

</OUTPUT>

/usr/xpg4/bin/grep -E "<(ns1SmilieroviderErrorText)>.*</\1>" sample.txt

<OUTPUT>

No OUTPUT & -o is an illegal Operation

</OUTPUT>
# 7  
Old 02-24-2011
On Solaris always use /usr/xpg4/bin/awk.
What is your actual input file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print between pattern without spaces

I seem to have hit a curious problem where sed and awk based regex do not seem to work. Perhaps I am missing a switch to look within the same line and not across lines. I have input as follows: ... (4 Replies)
Discussion started by: jamie_123
4 Replies

2. Shell Programming and Scripting

awk print string with removing all spaces

Hi all, I want to set 10 set of strings into a variable where: removing all spaces within each string change the delimiter from "|" to "," Currently, I've the below script like this:Table=`ten character strings with spaces in-between and each string with delimiter "|" | tr -d ' ' |... (7 Replies)
Discussion started by: o1283c
7 Replies

3. Shell Programming and Scripting

Print a specific number of spaces

i'm looking for a command that allows me to print a specific number of spaces which i will provide. something as simple as: spaces=4 printf " " * $spaces i'm looking for somethign that'll allow me to print a specific amount of spaces on a line. can awk be used for this? (4 Replies)
Discussion started by: SkySmart
4 Replies

4. Shell Programming and Scripting

print columns with spaces

Hi All I've a file which is similar to the one given below column1 coulmn2 column3 column4 A B C D X Y F G H I would like to get it in this format A|B|C|D ||X|Y F||G|H Is... (4 Replies)
Discussion started by: Celvin VK
4 Replies

5. UNIX for Dummies Questions & Answers

using tr to print spaces between lines

hi forum i was wondering can you use tr to print out a file like this i see that there is no way you could do that i feel i see that there is no way you could do that i feel i see that there is no way you could do that i feel i see that there is no way you could do that i feel i see that... (2 Replies)
Discussion started by: ShinTec
2 Replies

6. UNIX Desktop Questions & Answers

How to print several pages only text without spaces among

1 I open pdf file - it has empty borders of space without text 2 I want to print 9 pages to save paper & eyes 3 In Okular i choose print - 9 pages. And I have no option for adjusting text to text (to print without spaces among 9 pages). What program can you recommend to me for this... (1 Reply)
Discussion started by: Xcislav
1 Replies

7. Shell Programming and Scripting

Print filenames with spaces using awk

Hello all, I want to list the file contents of the directory and number them. I am using la and awk to do it now, #ls |awk '{print NR "." $1}' 1. alpha 2. beta 3. gamma The problem I have is that some files might also have some spaces in the filenames. #ls alpha beta gamma ... (7 Replies)
Discussion started by: grajp002
7 Replies

8. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

9. Shell Programming and Scripting

sed: replace string with another string (with spaces)

Hi I have an XML file with strings XABCD, XEFGHX and XIJKLX. I would like to replace XABCDX with "This is the first string", XEFGHX with "This is the second string" and XIJKLX with "This is the third string". What is the best way to implement this? Should I have a file with the data that is... (4 Replies)
Discussion started by: zmfcat1
4 Replies

10. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies
Login or Register to Ask a Question