Sponsored Content
Operating Systems Linux Red Hat Grep between two strings in shell Post 302829109 by RavinderSingh13 on Thursday 4th of July 2013 04:52:43 AM
Old 07-04-2013
Quote:
Grep between two strings in shell


Code:
<cisco:subname> <cisco:sptp>Cisco PortA Series</cisco:sptp> <cisco:aliasNameList xsi:nil="true"/> <cisco: owner xsi:nil="true"/> <cisco:subportname> <cisco:cpt>Cisco SubPort B Series</cisco:cpt> <cisco:aliasNamesubList xsi:nil="true"/> <cisco:userLabel xsi:nil="true"/> </cisco:subportname> </cisco:subname>


in the above xml file how to get the data between <cisco:subportname> and </cisco:subportname>

Hello,

Kindly check with this too.

Code:
$ awk '/\<cisco:subportname\>/','/\<\/cisco:subportname\>/' File

Output will be as follows.


Code:
 
                      <cisco:subportname>
                 <cisco:cpt>Cisco SubPort B Series</cisco:cpt>
                 <cisco:aliasNamesubList xsi:nil="true"/>
                 <cisco:userLabel xsi:nil="true"/>
               </cisco:subportname>

Thanks,
R. Singh

---------- Post updated at 03:52 AM ---------- Previous update was at 03:48 AM ----------

Quote:
Posted by Don

Try something like:


Code:
awk '$1 == "</cisco:subportname>" { p = 0 next}p$1 == "<cisco:subportname>" { p = 1}' file

If you are using a Solaris system, use /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk instead of /usr/bin/awk or /bin/awk .


That is excellent code Don, could you please explain me, as I am not able to see any if or print statement but it gives exactly same output.

I will be grateful to you.



Thanks,
R. Singh
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to concatenate two strings or several strings into one string in B-shell?

like connect "summer" and "winter" to "summerwinter"? Can anybody help me? thanks a lot. (2 Replies)
Discussion started by: fontana
2 Replies

2. Shell Programming and Scripting

want to grep only strings in a file?

Hai, Just want to print only alphanumeric in a file ex:- fdsdsklf#@^%$#hf output:- fdsdsklfhf plz, help me:o (5 Replies)
Discussion started by: balan_mca
5 Replies

3. Shell Programming and Scripting

Grep Multiple Strings

Hi, Can any one pelase tell me how to grep multiple strings from multiple files in a singel folder? grep -E "string1|string2|string3|string4|string..." its taking lots of time.. can any please tell me fast grep??? URGENT (10 Replies)
Discussion started by: durgaprasad
10 Replies

4. Shell Programming and Scripting

grep two strings in a file..

Hello All, I have a big file about 1000 lines. Now i am trying to grep a particular string and printing the lines from the string. say for example in 500th line i have the date as "Mon Wed 14 20:15:24 2010". now i in my case i need to grep the combination of the strings "Mon Wed 14" and the... (7 Replies)
Discussion started by: intiraju
7 Replies

5. Shell Programming and Scripting

Can't grep multiple strings

I have a script that periodically checks the Apache error_log to search for a specific error that causes it to hand and, if found, it restarts the service. I recently found another error that forces it to hand and won't serve pages until it is reset. What I'm trying to do is to get the script to... (3 Replies)
Discussion started by: cfjohnsn
3 Replies

6. Shell Programming and Scripting

Grep 2 same strings in a same line??

I have this code TrackingId:1362412470675;MSISDN:; INFO - number of clietns:3:Received response is: EMSResponse , protocolVersion=5, purchaseOptions=null, serviceData=ServiceData , screenData=CanvasData ]], title=null, titleResource=MessageResource], screenType=null]], serviceId=idBamboo,... (7 Replies)
Discussion started by: nikhil jain
7 Replies

7. Shell Programming and Scripting

GREP between last occurrences of two strings

Hi I have the server.log file as: Server Stopped ABC DEF GHI JKL Server Started MNO PQR STU Server Stopped VWX YZ ABC Server Started Server Stopped 123 456 789 (9 Replies)
Discussion started by: ankur328
9 Replies

8. Shell Programming and Scripting

Grep for strings

Hi, Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36 How can I grep for the strings chrome and safari from a file, and if chrome print Chrome/40.0.2214.94 to a file and also count the number of times chrome is found? ... (4 Replies)
Discussion started by: cyberfrog
4 Replies

9. Shell Programming and Scripting

Grep strings for different cases

Hi All, Good morning I have a below code which is working & getting expected output. the problem in this code is it is executing 3 if conditions, my requirement is suppose if first condition is success then it should print echo statement & exit from if condition else if the 1st if condition... (4 Replies)
Discussion started by: sam@sam
4 Replies

10. Programming

Python or Shell script to Grep strings from input file and output in csv format

Hi Experts, I am writing a python script to grep string from file and display output in csv file as in attached screenshot https://drive.google.com/file/d/1gfUUdfmQma33tz65NskThYDhkZUGQO0H/view Input file(result_EPFT_config_device) Below is the python script i have prepared as of... (1 Reply)
Discussion started by: as7951
1 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 04:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy