- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: change format of file contents
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 01:12 AM
11-05-2004 01:12 AM
I have quite high number of files which contains ip address as well as URL.
File looks like below:
======================
206.251.29.10
218.102.48.99
213.158.72.99
playboy.com
admotion.com.ar
bannerlandia.com.ar
austria-chart.at
teleweb.at
admaster.candela.com.au
fairfax.com.au
=======================
Now i want to change all URL like below:
.*://.*.playboy.com/.*
And all IP address like below
.*://206\.251\.29\.10/.*
What is the best possible way to do this?
If it can be done in vi editor then also
pl. provide me syntax and also if it is possible by other way like sed, awk, perl then also it will great help to solve my problem.
regards
Tapas
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 01:23 AM
11-05-2004 01:23 AM
Re: change format of file contents
#
testfile contains al your input contents.
while read line; do
echo $line | grep -q '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'
if [[ $? -eq 0 ]]; then
echo $line | awk -F "." '{ print ".*://.*."$1"\."$2"\.$3\."$4"/.*" }'
else
echo $line | awk '{ print ".*://.*."$0"/.*" }'
fi
done < testfile
--- Output ---
.*://.*.206.251.$3.10/.*
.*://.*.218.102.$3.99/.*
.*://.*.213.158.$3.99/.*
.*://.*.playboy.com/.*
.*://.*.admotion.com.ar/.*
.*://.*.bannerlandia.com.ar/.*
.*://.*.austria-chart.at/.*
.*://.*.teleweb.at/.*
.*://.*.admaster.candela.com.au/.*
.*://.*.fairfax.com.au/.*
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 01:29 AM
11-05-2004 01:29 AM
SolutionSlight modification on ip parsing as,
# while read line; do
echo $line | grep -q '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'
if [[ $? -eq 0 ]]; then
echo $line | awk -F "." '{ print ".*://"$1"\."$2"\.$3\."$4"/.*" }'
else
echo $line | awk '{ print ".*://.*."$0"/.*" }'
fi
done < testfile
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 01:39 AM
11-05-2004 01:39 AM
Re: change format of file contents
create
BEGIN{FS="."}
{printf ("%s",".*://");for (IA=1;IA
END{}
as zz.awk
then
awk -f zz.awk yourfile
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 01:53 AM
11-05-2004 01:53 AM
Re: change format of file contents
Make it in 2 steps:
grep "^[a-z]"
grep "^[0-9]"
I suppose you can do it with awk but i don't well know this command.
Rgds
JMB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 02:11 AM
11-05-2004 02:11 AM
Re: change format of file contents
Muthukumar's is working fine.
Michale in your script even in url's . is coming with \. in front and also
in begining of url it will be .*://.*.(url) and in IP it will be .*://ipwith.(dot)separated by\. and lastly /.* will be added in both.
Rgds
Tapas