Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-26-2006, 11:17 AM
|
#1
|
Member
Registered: Oct 2005
Posts: 50
Rep:
|
Script
Hi guys,
I need help on how to start a script. I have archives or list of people who borrow things from me. I am using centos linux and I need help on how to start to write a script which extracts certain information like the name, device#, mac addie, leasing date instead all the other junk stored in the file. I want these information to be in comma delimited text file that could be run from desktop or something.
I read a lot on db extracting but this is not a database, I know how to put in stuff in database from comma delimited file but I don't know how to make a script take an input file, extract certain information and save it in comma delimited text file.
Any pointers or tutorial or anything will be greatly appreciated. Thanks.
--p
|
|
|
01-26-2006, 11:52 AM
|
#2
|
Member
Registered: Jun 2004
Posts: 60
Rep:
|
Depending on the format of the file, sed or awk should work to break it up for you.
|
|
|
01-26-2006, 12:21 PM
|
#3
|
Member
Registered: Oct 2005
Posts: 50
Original Poster
Rep:
|
I kind of didn't understand that. Can you please expand on what you mean? Thank you. Is it grammer for writing script?
--p
|
|
|
01-26-2006, 12:30 PM
|
#4
|
Member
Registered: Jun 2004
Posts: 60
Rep:
|
sed or awk are programs that can be used to edit files. Should be able to read a file into the program and have it parse through the file, looking for spaces, commas, colons, words, etc.. and use those "landmarks" to format the file into the format you want it in.
This link might help to understand what I am talking about.
http://builder.com.com/5100-6372-1050917.html
Sorry, I am not very good with sed and awk. Wish I was, they can be very useful.
Good luck.
|
|
|
01-26-2006, 11:08 PM
|
#5
|
LQ Guru
Registered: Jan 2001
Posts: 24,149
|
man sed
man awk
man grep
This sounds like it would be a good job for perl even.
www.perl.org
|
|
|
01-27-2006, 11:18 AM
|
#6
|
Member
Registered: Oct 2005
Posts: 50
Original Poster
Rep:
|
Thanks I will look into them. But one more question. Is this good enough for high level scripting? Like if
lease IP{
starts 3 2002/02/05 05:57:46;
ends 3 2003/05/26 06:57:46;
set ddns-fwd-name = "YOUR-dns";
set ddns-txt = "somerandomintegers";
client-hostname "YOUR-randints";
}
host vwilma-1 {
dynamic;
hardware ethernet 00:02:40:24:af:23;
}
and with this information from a file i can produce a script that can produce a comma-delimited text file in the format "user, device #, mac addr, ip addr, lease start, lease end".
Will it work with this kind of information? How do I go about doing this. Thanks again.
--p
|
|
|
01-27-2006, 01:31 PM
|
#7
|
Member
Registered: Jun 2004
Posts: 60
Rep:
|
Yes, you should be able to write a script that will format that for you. I have seen perl scripts that do something similar to this.
|
|
|
01-28-2006, 09:17 AM
|
#8
|
Member
Registered: Oct 2005
Posts: 50
Original Poster
Rep:
|
May be you can show an example? It would be nice to visualize. I am not too much involved with perl but I do have hands on on php, mysql etc....
Thanks for all the help. I really appreciate it. It is helping me a lot.
--p
|
|
|
01-30-2006, 12:48 PM
|
#9
|
Member
Registered: Oct 2005
Posts: 50
Original Poster
Rep:
|
Also, What kind of scripting language supports or integrates best for this problem?
|
|
|
01-30-2006, 02:57 PM
|
#10
|
LQ Guru
Registered: Jan 2001
Posts: 24,149
|
Probably in your case, you'd have to break the format up, you could probably use grep to search for each of your terms or columns then use the split function to lay out each column for your comma separated file or output and then use the join function within perl to rebuild it how you want.
perldoc -f <perl function>
So:
perldoc -f split # will give you the documentation on the split function.
This is definitly a job for perl..
|
|
|
All times are GMT -5. The time now is 11:09 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|