nixCraft Linux Forum

nixCraft

Linux / UNIX 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

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-04-2008, 11:34 AM
Junior Member
User
 
Join Date: Feb 2008
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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
  #2 (permalink)  
Old 12-04-2008, 03:26 PM
Junior Member
User
 
Join Date: Feb 2008
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Prahlad is on a distinguished road
Default

hmmm so sad ... unlucky me

Still no answer
Reply With Quote
  #3 (permalink)  
Old 13-04-2008, 01:45 AM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 708
Thanks: 15
Thanked 19 Times in 18 Posts
Rep Power: 10
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
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.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote
  #4 (permalink)  
Old 23-04-2008, 11:25 PM
Junior Member
User
 
Join Date: Apr 2008
OS: Debian
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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


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 Off


Similar Threads

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


All times are GMT +5.5. The time now is 12:55 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 37 38