The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   awk, cut, and sed (http://hintsforums.macworld.com/showthread.php?t=105862)

tlarkin 09-29-2009 03:21 PM

awk, cut, and sed
 
I just can't seem to totally wrap my head around pulling out strings of data from commands with awk, cut, and sed.

I can get grep, but grep isn't always the best answer.

Anyone got any good resources explaining these binaries?

Hal Itosis 09-29-2009 03:39 PM

I think cut is a fairly limited tool (no regex support or even wildcarding that i know of). I would say a google on these...

'sed tutorial'
'awk tutorial'

...would probably yield mass quantities. It did for me in the past. Naturally, hunting around oreilly.com will produce both online articles and books on the subject. I "cut" my teeth on 'Classic Shell Scripting' where chapter 3 provided most of what i use now (other than man awk and man sed and man regex, etc). But it's certainly possible to find an entire book about them. The 'The GNU Awk User's Guide' over at gnu.org is fairly definitive... as is the 'Advanced Bash-Scripting Guide' over at tldp.org

bb5ch39t 09-29-2009 04:15 PM

GNU sed documentation:

http://www.gnu.org/software/sed/manual/

GNU awk documentation:

http://www.gnu.org/software/gawk/manual/

nice article on awk:

http://www.ibm.com/developerworks/li...ry/l-awk1.html
http://www.ibm.com/developerworks/li...ry/l-awk2.html
http://www.ibm.com/developerworks/li...ry/l-awk3.html

tlarkin 09-29-2009 06:30 PM

Thank you book marked those for when I got more time to get down to it. However, I have a project on the back burner that I want to develop an open source package for OS X and release it for free, which will use a lot of under the hood scripts to accomplish what I want it to do.

Thanks

Tom

brettgrant99 09-29-2009 09:47 PM

Awk is good for 1 liners. Much more than that and perl is probably better. Awk works oddly on Macs - it is pretty slow. I've never tried compiling it. I seem to recall that there is a post here somewhere that explains why it is slow.

Sed, well, I've never managed to do anything in sed other than substitutions.

The o'reilley book sed and awk is a good one. Just buy an old edition off of ebay for a couple of bucks.

Is this the hardware inventory project?

Good Luck,
Brett

tlarkin 09-30-2009 09:51 AM

Quote:

Originally Posted by brettgrant99 (Post 555043)
Is this the hardware inventory project?

Good Luck,
Brett

No, but they want me to develop an app that will basically spy on a student when deployed and take screen shots of what they are doing. I guess the FCC puts out federal regulations that we, as a public school system, are required to filter the students and we have to audit our filtering. I guess there is a group of students who are breaking AUP and always getting away with it.

So, I wrote a script that takes screen shots every 5 minutes, puts a stamp of the current user name with the time and date, and then saves them in a private folder hidden in the under the hood Unix.

I just haven't had time to get back to it yet to wrap it up in a PKG and be able to give it to "the Internet Police" here at work.

There are apps out there that do this, but they are $30 to $40 per a license and well, we have over 6,000 macbooks and probably another 3,000 Mac desktops.

I was also just told we are finally scrapping all of our eMacs and replacing them with new iMacs in the middle schools, so I will be imaging and rolling those out as well soon.

brettgrant99 09-30-2009 10:48 AM

Just out of curiosity, is just for school provided internet, or at all times?

If just at school, it seems like you could send all the info to a database and be able to do some mining.

But then you are back to perl :)

Brett

tlarkin 09-30-2009 11:00 AM

Since they take the laptops off campus, they need to be filtered at all times. If you want to read the nitty gritty of it you can look up CIPA (child internet protection act) which outlines all the federal stuff we are forced to do with children and the internet.

We actually got audited by the feds last year, and they came out and audited our filtering systems. I guess if you don't comply you can lose erated funding? I am not sure the exact penalties of not being in compliance but they are something we don't want.

Every time a student complains to me about Internet filtering I tell them it is a federal mandate and for them to write their representatives in government if they want it changed.:)

trevor 09-30-2009 01:41 PM

Quote:

Originally Posted by tlarkin (Post 555095)
Every time a student complains to me about Internet filtering I tell them it is a federal mandate and for them to write their representatives in government if they want it changed.:)

Eddie Chochran wrote way back in 1958:

Well I called my congressman and he said Quote:
"I'd like to help you son but you're too young to vote"

Trevor

tlarkin 09-30-2009 01:44 PM

Quote:

Originally Posted by trevor (Post 555123)
Eddie Chochran wrote way back in 1958:

Well I called my congressman and he said Quote:
"I'd like to help you son but you're too young to vote"

Trevor

Some of them are 18 and 19 years old they can vote, but most cannot.

brettgrant99 09-30-2009 03:25 PM

Quote:

Originally Posted by tlarkin (Post 555095)
Every time a student complains to me about Internet filtering I tell them it is a federal mandate and for them to write their representatives in government if they want it changed.:)

Why don't you just tell them to provide their own computer? The way that I read the little blurb is that this is because the money that buys the computers comes from the government.

How do you make sure that they aren't hacking? Do you have the authority to disable the computer if the student doesn't comply with the policy?

Just curious,
Brett

tlarkin 09-30-2009 03:29 PM

Quote:

Originally Posted by brettgrant99 (Post 555162)
Why don't you just tell them to provide their own computer? The way that I read the little blurb is that this is because the money that buys the computers comes from the government.

How do you make sure that they aren't hacking? Do you have the authority to disable the computer if the student doesn't comply with the policy?

Just curious,
Brett

yes, as they aren't personal property. They are property of the state technically or school district. They sign an AUP (acceptable usage policy) that clearly outlines they are not private machines and that they can be taken and they can be watched.

It is just like working at a company, except in the school system you get in trouble and maybe at worst get suspended where as in the real world you lose your job.

I have extensive reporting policies in Casper with email notifications and of course ARD admin. To be honest most of the time I am way too busy to spy, but if some school administrator or director asks me to pull info on a certain laptop I do it. Plus the reports and usage logs are there as a paper trail.

ghostdog74 10-12-2009 08:46 AM

Quote:

Originally Posted by brettgrant99 (Post 555043)
Awk is good for 1 liners.

And also for simple to complex file/string text manipulation, or use it as a simple programming language, not just for one liners.

tlarkin 10-12-2009 08:49 AM

Well I am using it more and I think I got the hang of it for plucking out info that I need.

lowfokus 10-26-2009 11:56 PM

Quote:

Originally Posted by tlarkin (Post 555095)
Since they take the laptops off campus, they need to be filtered at all times. If you want to read the nitty gritty of it you can look up CIPA (child internet protection act) which outlines all the federal stuff we are forced to do with children and the internet.

We actually got audited by the feds last year, and they came out and audited our filtering systems. I guess if you don't comply you can lose erated funding? I am not sure the exact penalties of not being in compliance but they are something we don't want.

Every time a student complains to me about Internet filtering I tell them it is a federal mandate and for them to write their representatives in government if they want it changed.:)

I googled it, and came up with this:
CIPA does not require the tracking of Internet use by minors or adults.
from here:
http://www.fcc.gov/cgb/consumerfacts/cipa.html

Does that make your job easier?

tlarkin 10-27-2009 12:17 AM

Quote:

Originally Posted by lowfokus (Post 559012)
I googled it, and came up with this:
CIPA does not require the tracking of Internet use by minors or adults.
from here:
http://www.fcc.gov/cgb/consumerfacts/cipa.html

Does that make your job easier?

No, because to qualify for erate technology you have to be fully CIPA compliant with erate's standards. We got audited last year. The tracking is policy based on the Acceptable Usage Policies my organization has put in place.

tw 10-27-2009 01:49 AM

Quote:

Originally Posted by tlarkin (Post 559015)
No, because to qualify for erate technology you have to be fully CIPA compliant with erate's standards. We got audited last year. The tracking is policy based on the Acceptable Usage Policies my organization has put in place.

not that it's at all helpful, but there's something seriously wrong in your neck of the woods. Funding dependent on semi-legal surveillance of minors? Have you considered that if one of those students has a picture exchange with their girl/boy-friend that gets a little raunchy, and your software records and stores it, you would actually be in violation of federal child pornography laws? You probably wouldn't get convicted, of course, but still... Do you have parental permission (or at least waivers) for this kind of intrusive observation?

Too bad I'm not a lawyer; I smell money here... :)

acme.mail.order 10-27-2009 01:56 AM

What info are you after? If this is being done on a local machine then `screencapture` with date for the filename should be all you need.

Do you want to grab the iSight image as well?

Surprised some libertarian parent hasn't sued someone over the monitoring.

tlarkin 10-27-2009 09:36 AM

Quote:

Originally Posted by acme.mail.order (Post 559021)
What info are you after? If this is being done on a local machine then `screencapture` with date for the filename should be all you need.

Do you want to grab the iSight image as well?

Surprised some libertarian parent hasn't sued someone over the monitoring.

Oh, they sign an acceptable usage policy and so does the parent, which clearly states nothing you do on this computer is private.

I have a launchd item written and a shell script that uses the screen capture command, it then outputs a file to a hard coded destination. It names the file the current logged in user and adds a date stamp to the file name. I used awk to get the current logged in user since launchd scripts run as root.

My problem is, I want a GUI that will control and unload and load the launchd item, will set the directory to save the file in, and will set the interval of how often the script runs, eg every 5 minutes, every 2 minutes and so forth. Then I want an option in the GUI front end that will unload the launchd item and will stop it from running.

I know how to do all of this from the command line, I have no clue how to tie it to buttons on a little interface and have it write to the files it installs to configure the launchd and script settings.

I think I may pick up a book or two on xcode and objective c.

acme.mail.order 10-27-2009 10:08 AM

Seems like a perfect job for Applescript and / or Interface Builder.

There's a slightly dated thread specifically about building a GUI for a shell script around someplace.

tw 10-27-2009 11:16 AM

Quote:

Originally Posted by tlarkin (Post 559062)
I know how to do all of this from the command line, I have no clue how to tie it to buttons on a little interface and have it write to the files it installs to configure the launchd and script settings.

are you using 10.5 or 10.6? in 10.5 (as acme suggests) you can use applescript studio and interface builder, and it's actually very easy to do something like this. open xcode and start a new applescript application project. double-click on the .xib file (which opens a default interface in interface builder) and build the GUI by adding stock buttons, text fields, and etc. then you click on each button. open the inspector window and then click on each element in turn - the last panel in the inspector window lets you attach the the element to your script, set the name of the element, and select any actions you want to code (like 'click'). once that's all set to your liking, go back to xcode and add your code - IB will have made (for instance) an 'on click' handler, so add a bunch of if statements to check (say) the name of the button that got clicked (all button clicks will go to the same 'on click' handler), and run the appropriate shell command using do shell script. well, setting the time interval will be a bit trickier, because you'll need to use system events to modify the launch daemon plist file and then unload and reload it...

tlarkin 10-27-2009 11:28 AM

Quote:

Originally Posted by tw (Post 559073)
are you using 10.5 or 10.6? in 10.5 (as acme suggests) you can use applescript studio and interface builder, and it's actually very easy to do something like this. open xcode and start a new applescript application project. double-click on the .xib file (which opens a default interface in interface builder) and build the GUI by adding stock buttons, text fields, and etc. then you click on each button. open the inspector window and then click on each element in turn - the last panel in the inspector window lets you attach the the element to your script, set the name of the element, and select any actions you want to code (like 'click'). once that's all set to your liking, go back to xcode and add your code - IB will have made (for instance) an 'on click' handler, so add a bunch of if statements to check (say) the name of the button that got clicked (all button clicks will go to the same 'on click' handler), and run the appropriate shell command using do shell script. well, setting the time interval will be a bit trickier, because you'll need to use system events to modify the launch daemon plist file and then unload and reload it...

All 10.5 as I am resisting upgrading to 10.6. I haven't ever really messed with that stuff but I can write in shell and I know a bit of Apple Script.


All times are GMT -5. The time now is 10:17 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.