LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-26-2010, 01:57 AM   #1
eliote
Member
 
Registered: Jun 2010
Distribution: Ubuntu
Posts: 39

Rep: Reputation: 0
text processing and cutting


Hi all,

I've ran a CentOS 5 for which i want to change the hostname by script.
the desired clue is to replace the previous hostname with the one which asked from the user who executing the script. below is content of /etc/hosts.

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 example.domain.com example localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

how to process the "example.domain.com" "example" using awk command and replace with new one?
 
Old 10-26-2010, 02:40 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
What have you tried? This is a fairly trivial problem. Hint: each name you have quoted is a field.
 
Old 10-26-2010, 02:50 AM   #3
eliote
Member
 
Registered: Jun 2010
Distribution: Ubuntu
Posts: 39

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grail View Post
What have you tried? This is a fairly trivial problem. Hint: each name you have quoted is a field.
so, how to determine the specified fields in the text?!
 
Old 10-26-2010, 03:28 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Quote:
so, how to determine the specified fields in the text?!
Assuming I understand what you mean here, from your example:

"example.domain.com" - $2
"example" - $3
 
  


Reply



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
Text-processing and loops ... skipdashu Linux - Newbie 10 04-30-2009 09:51 PM
[bash] cutting text with sed Erhnam Programming 3 02-11-2005 04:31 AM
cutting down contents of text file kam_kenneth Linux - Newbie 2 05-22-2004 01:16 AM
text editingor processing exodist Linux - General 2 11-29-2003 10:24 PM
text processing Gantrep Linux - General 4 02-17-2003 10:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:44 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