LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-05-2007, 10:40 PM   #1
Buddhike G
Member
 
Registered: Jun 2007
Distribution: RHEL, CentOS, Solaris
Posts: 63

Rep: Reputation: 16
need help to read a file


I've a text file containing more than 100 blocks of data in the following format with different values for variables. And i want to write a shell script to read host_name and the address from each block and store in an another file can anybody help me to write that.



host_name Test_server
alias Test_server
address 10.40.2.3
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,u,r
check_command check-host-alive


Thanx in advance !!!
Buddhike G
 
Old 12-05-2007, 11:23 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,308

Rep: Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744
Code:
grep -e host_name -e address infile > outfile
 
Old 12-05-2007, 11:53 PM   #3
Buddhike G
Member
 
Registered: Jun 2007
Distribution: RHEL, CentOS, Solaris
Posts: 63

Original Poster
Rep: Reputation: 16
Thanx ! it worked !

But the output prints as

host_name Test_server
address 10.40.2.3
. .
. .
. .

and so on ..

but I want to print it as this

Test_server <TAB> 10.40.2.3
. .
. .
. .


Thanx for any help.
Buddhike G


Quote:
Originally Posted by chrism01 View Post
Code:
grep -e host_name -e address infile > outfile
 
Old 12-06-2007, 02:44 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
If the structure of the blocks is always identical:
Code:
awk '/host_name/{printf "%s\t",$2};/address/{print $2}' infile > outfile

Cheers,
Tink
 
Old 12-06-2007, 02:50 AM   #5
Buddhike G
Member
 
Registered: Jun 2007
Distribution: RHEL, CentOS, Solaris
Posts: 63

Original Poster
Rep: Reputation: 16
Thanx a lot!!! It worked !
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
web server (fedora core 5) became read-only file system after i upload a file nggs8411 Linux - Server 1 03-26-2007 09:23 AM
How to read .chm file in fedora, can't mount ntfs file system ishti_du Linux - Newbie 12 03-06-2007 03:27 AM
Java File Processing using Scanner; Can't get it to read file in running directory xemous Programming 2 09-26-2006 06:13 PM
how do I make a read-only file NOT read-only? robster Linux - General 1 02-17-2004 09:11 PM
Change from Read only to Read Write File System? justiceisblind Linux - Newbie 3 03-03-2002 07:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration