Command to get URL under string "SIT"

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Command to get URL under string "SIT"
# 1  
Old 02-10-2016
Command to get URL under string "SIT"

Hi All,

I have a requirement where I need to get all https URL's under config file SIT. example :

Code:
config environment="SIT"

<URL>https://yahoo.com</URL>

There are 100 files.xml and I need to search every .xml file and get URL's.

I tried with below command , but I'm getting URL's from 20 + folders, but I need from all 100 files.

Code:
find . -name “*.xml” |xargs grep -n “https”


Last edited by Don Cragun; 02-11-2016 at 01:11 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 02-11-2016
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)



Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 3  
Old 02-11-2016
What error messages are being printed by find, xargs, and grep?

What are the exact names of the *.xml files that are not being searched properly?

Show us an example of the URLs in one of the files that are not being extracted properly by the command you showed us (using CODE tags).
# 4  
Old 02-16-2016
Sorry for late reply, I'm using below command:

Code:
find . -name “*.xml” |xargs grep -n “SIT”

my config file has details of
Code:
"DEV, SIT,UAT and PROD"

as below:
Code:
<configs>
	
	<config environment="DEV">
		<routingURL>https://yahoo.com</routingURL>
	</config>
	<config environment="SIT">
		<routingURL>https://google.com</routingURL>
	</config>
	<config environment="UAT">
		<routingURL>https://yahoo1.com</routingURL>
	</config>
	<config environment="PROD">
		<routingURL>https://yahoo2.com</routingURL>
	</config>
</configs>

The folder I'm searching has 100 xmls' and I need to traverse from each files and get all https exactly under SIT.

The command I'm using is showing output of URL's which has SIT has the part of it.

Please suggest.

Thanks,
VJ
# 5  
Old 02-16-2016
You didn't mention what operating system you're using (which always helps when you ask for help in this forum), but if you your version of grep includes a -A option (which is not required by the standards), an easy way to do what you seem to want would be:
Code:
grep -A1 '"SIT"' *.xml |grep 'https'

An alternative would be:
Code:
awk '/"SIT"/+1 && /https:/' *.xml

As always, if you want to try the awk command on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
# 6  
Old 02-17-2016
Thanks Don. The operating system I'm using is LINUX.

I can see its printing the URL under SIT, but I forgot to mention that I need to search under different folders and so I have used below command

Code:
find . -name "*.xml" |xargs grep -A1 "SIT" | grep 'https'

It is actually printing everything , so I need values of folder which has
Code:
*.xml

and go into that and get URL which is under SIT.
# 7  
Old 02-17-2016
@Don Cragun: Please explain awk '/"SIT"/+1 && /https:/' *.xml
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

2. Shell Programming and Scripting

How to avoid "Too many arguments" error, when passing a long String literal as input to a command?

Hi, I am using awk here. Inside an awk script, I have a variable which contains a very long XML data in string format (500kb). I want to pass this data (as argument) to curl command using system function. But getting Too many arguments error due to length of string data(payloadBlock). I... (4 Replies)
Discussion started by: cool.aquarian
4 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

5. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

6. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

7. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

8. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

9. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

10. Shell Programming and Scripting

input string="3MMTQSZ348GGMZRQWMJM4SD6M";output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6

input string="3MMTQSZ348GGMZRQWMJM4SD6M" output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6M" using linux shell script (4 Replies)
Discussion started by: pankajd
4 Replies
Login or Register to Ask a Question