nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

How to print some lines from a file

This is a discussion on How to print some lines from a file within the Shell scripting forums, part of the Development/Scripting category; Hello Every one I have a problem with me which i want to solve using shell script. I want to ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 11:34 AM
Junior Member
User
 
Join Date: Feb 2008
My distro: Debian
Posts: 5
Rep Power: 0
Prahlad is on a distinguished road
Default How to print some lines from a file

Hello Every one

I have a problem with me which i want to solve using shell script.

I want to display lines from my apache configuration. I want some thing like this ...

Script should display entries from <VirtualHost Ip.Ip.Ip.Ip> to sever.domain.com only
and all occurrence of domain.com should be replaced by test.com.

Like my original entry is as below.

==========
<VirtualHost Ip.Ip.Ip.Ip>
something
something
....
ServerName domain.com
ServerAlias server.domain.com
something
something
......
</VirtualHost>


O/p should be as given below.

---------
<VirtualHost Ip.Ip.Ip.Ip>
something
something
....
ServerName test.com
ServerAlias server.test.com
</VirtualHost>
--------

=========

Please guide me with this.

Thanks,
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-12-2008, 03:26 PM
Junior Member
User
 
Join Date: Feb 2008
My distro: Debian
Posts: 5
Rep Power: 0
Prahlad is on a distinguished road
Default

hmmm so sad ... unlucky me

Still no answer
Reply With Quote
  #3 (permalink)  
Old 04-13-2008, 01:45 AM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 576
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

I'm not sure what exactly you want but patterns (text beween two words or pattern) can be selected using sed:
Code:
sed -n '/WORD1/,/WORD2/p' httpd.conf
sed -n '/<VirtualHost*/,/<\/VirtualHost>/p' httpd.conf
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #4 (permalink)  
Old 04-23-2008, 11:25 PM
Junior Member
User
 
Join Date: Apr 2008
My distro: Debian
Posts: 1
Rep Power: 0
Tidimalo is on a distinguished road
Red face Searching for a file

I have a problem of searchin files using scripts
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
How to make leafpad to print satimis Linux software 0 12-25-2007 07:36 PM
Script to display number of lines and words from a file newbewie Shell scripting 2 12-07-2007 10:37 PM
Load balancing pooling print jobs using CUPS print queues raj Getting started tutorials 0 01-16-2007 09:08 PM
print data to txt rock Shell scripting 1 03-10-2006 02:01 AM
Calculations across different lines & columns of a file Guest Shell scripting 2 09-16-2005 04:18 AM


All times are GMT +5.5. The time now is 11:20 AM.


Powered by vBulletin® Version 3.7.3 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36