LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 01-26-2006, 11:17 AM   #1
LAdProg2005
Member
 
Registered: Oct 2005
Posts: 50

Rep: Reputation: 15
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
 
Old 01-26-2006, 11:52 AM   #2
bmeckle
Member
 
Registered: Jun 2004
Posts: 60

Rep: Reputation: 15
Depending on the format of the file, sed or awk should work to break it up for you.
 
Old 01-26-2006, 12:21 PM   #3
LAdProg2005
Member
 
Registered: Oct 2005
Posts: 50

Original Poster
Rep: Reputation: 15
I kind of didn't understand that. Can you please expand on what you mean? Thank you. Is it grammer for writing script?

--p
 
Old 01-26-2006, 12:30 PM   #4
bmeckle
Member
 
Registered: Jun 2004
Posts: 60

Rep: Reputation: 15
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.
 
Old 01-26-2006, 11:08 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 270Reputation: 270Reputation: 270
man sed
man awk
man grep

This sounds like it would be a good job for perl even.

www.perl.org
 
Old 01-27-2006, 11:18 AM   #6
LAdProg2005
Member
 
Registered: Oct 2005
Posts: 50

Original Poster
Rep: Reputation: 15
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
 
Old 01-27-2006, 01:31 PM   #7
bmeckle
Member
 
Registered: Jun 2004
Posts: 60

Rep: Reputation: 15
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.
 
Old 01-28-2006, 09:17 AM   #8
LAdProg2005
Member
 
Registered: Oct 2005
Posts: 50

Original Poster
Rep: Reputation: 15
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
 
Old 01-30-2006, 12:48 PM   #9
LAdProg2005
Member
 
Registered: Oct 2005
Posts: 50

Original Poster
Rep: Reputation: 15
Also, What kind of scripting language supports or integrates best for this problem?
 
Old 01-30-2006, 02:57 PM   #10
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 270Reputation: 270Reputation: 270
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..
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 05:19 AM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 12:00 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 11:23 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 05:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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