Re: awk question: replacing "%d%s" by "%d %s"
On Fri, 14 Jan 2011 17:53:04 +1030, Wayne Sierke wrote: > I suspect it is a transcription error by Robert in his email. > > From man awk: > >sub(r, t, s) > substitutes t for the first occurrence of the regular > expression > r in the string s. If s is not given, $0 is used. > > > So the correct syntax is: > > sub("[a-z]", " &", nr) Works in this version, thanks! Reduction of 7 lines of code. sub(from, to, where); is the correct form. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: awk question: replacing "%d%s" by "%d %s"
On Fri, 2011-01-14 at 07:17 +0100, Polytropon wrote: > On Thu, 13 Jan 2011 18:22:18 -0600 (CST), Robert Bonomi > wrote: > > True. But > > sub(nr,"[a-z]"," &"); > > > > does the trick. (tested on Freebsd 7.2) > > > > Explamation: "&" is a 'replacement side' magic incantation to the regex > > library that means 'that which was matched by the pattern regex'. > > Doesn't work on my 7-STABLE system (20080811), awk stops: > > awk: syntax error at source line 78 source file konvertieren.awk > context is > sub(nr, "[a-z]", " >>> &" <<< ); > awk: illegal statement at source line 79 source file konvertieren.awk > > But I'll keep your suggestion in the program source and test > it on 8 as soon as my "new" home system is ready to use. At > least, the & variant looks much better. I suspect it is a transcription error by Robert in his email. >From man awk: sub(r, t, s) substitutes t for the first occurrence of the regular expression r in the string s. If s is not given, $0 is used. So the correct syntax is: sub("[a-z]", " &", nr) Wayne ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: awk question: replacing "%d%s" by "%d %s"
On Thu, 13 Jan 2011 18:22:18 -0600 (CST), Robert Bonomi wrote: > True. But > sub(nr,"[a-z]"," &"); > > does the trick. (tested on Freebsd 7.2) > > Explamation: "&" is a 'replacement side' magic incantation to the regex > library that means 'that which was matched by the pattern regex'. Doesn't work on my 7-STABLE system (20080811), awk stops: awk: syntax error at source line 78 source file konvertieren.awk context is sub(nr, "[a-z]", " >>> &" <<< ); awk: illegal statement at source line 79 source file konvertieren.awk But I'll keep your suggestion in the program source and test it on 8 as soon as my "new" home system is ready to use. At least, the & variant looks much better. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: awk question: replacing "%d%s" by "%d %s"
> Date: Thu, 13 Jan 2011 06:28:19 +0100 > From: Polytropon > Subject: awk question: replacing "%d%s" by "%d %s" > > I'm aware that this is not an awk question list, but I'm confident there > are many awk gurus here who can surely help me with such a stupid > problem. I also know that I get more and more stupid myself for NOT being > able to solve this, even after... some nearly infinite time. :-) > > I have strings of the form either "" or > "". I catch them with > > if(match(nr, "[a-z]")) > ... > > where "nr" is the name of the string. What I need is a simple space > between and , so for example "12a" would get "12 a", > "6d" would get "6 d", and "58" would stay unchanged. I've tried with > split(), with array manipulation and could produce 10 lines of code that > didn't work as intended > (it produced "1122aa", "66dd" and "5588" according > to the examples above). > Obviously, sub(nr, "[a-z]", " [a-z]"); is nonsense. > True. But sub(nr,"[a-z]"," &"); does the trick. (tested on Freebsd 7.2) Explamation: "&" is a 'replacement side' magic incantation to the regex library that means 'that which was matched by the pattern regex'. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: awk question: replacing "%d%s" by "%d %s"
On Thu, Jan 13, 2011 at 12:28 AM, Polytropon wrote: > I have strings of the form either "" or > "". I catch them with ... > where "nr" is the name of the string. What I need > is a simple space between and , > so for example "12a" would get "12 a", "6d" would > get "6 d", and "58" would stay unchanged. I've tried This feels like it could be faster, but is reasonable: $ cat data.txt 1 12 3 1d 1dc 12d 12dc 123d 123dc 123dcb $ cat control.txt 1 12 3 1 d 1 dc 12 d 12 dc 123 d 123 dc 123 dcb $ awk < data.txt > experiment.txt '{ num = $1 ; sub(/[^0-9]+$/, "", num) ; lets = $1 ; sub(/^[0-9]+/, "", lets); print num " " lets }' ; diff -cw control.txt experiment.txt $ # The above puts a space at the end of the first 3 lines. If that is bad, try: $ awk < data.txt > experiment.txt '{ num = $1 ; sub(/[^0-9]+$/, "", num) ; lets = $1 ; sub(/^[0-9]+/, "", lets); if (length(lets)) { print num " " lets } else { print num } }' ; diff control.txt experiment.txt $ Tom -- http://EverythingSysadmin.com -- my blog (new posts Mon and Wed) http://www.TomOnTime.com -- my advice (more videos coming soon) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: awk question: replacing "%d%s" by "%d %s"
On Thu, 13 Jan 2011 01:00:17 -0500, Tom Limoncelli wrote: > $ awk < data.txt > experiment.txt '{ num = $1 ; sub(/[^0-9]+$/, "", > num) ; lets = $1 ; sub(/^[0-9]+/, "", lets); print num " " lets }' ; > diff -cw control.txt experiment.txt > $ # The above puts a space at the end of the first 3 lines. If that > is bad, try: > $ awk < data.txt > experiment.txt '{ num = $1 ; sub(/[^0-9]+$/, "", > num) ; lets = $1 ; sub(/^[0-9]+/, "", lets); if (length(lets)) { print > num " " lets } else { print num } }' ; diff control.txt experiment.txt > $ Thanks for your inspiration! I concluded that it is a possible way to split the string into two parts: not-numbers (letters) and numbers, and then recombining them in the desired way. Here's my code: if(match(nr, "[a-z]")) { z = nr; gsub(/[^0-9]+$/, "", z); b = nr; gsub(/[0-9]/, "", b); nr = sprintf("%s %s", z, b); } First catch all nr's that have a letter in it, then remove the letters in one copy, then the numbers in another one, and finally overwrite nr with the proper recombination that includes the space. Works as intended, FULLY. Thanks! -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: awk question (actively tail a file & notify when expression is found)
On Wed, 22 Apr 2009 12:38:47 -0700, Evuraan::ഏവൂരാന് wrote: > but this below, does not work > > tail -f /var/log/apache2/access.log |awk ' /192.168.1.100/ { print > $0 | "mail m...@email.address "}' I would suggest to keep the system() approach: tail -f /var/log/apache2/access.log | awk '/192.168.1.100/ { system(sprintf("echo %s | mail m...@email.address", $0)); }' > Any pointers would be much appreciated. It should work, but I'm sure someonle else will soon show you some more elegant way. :-) -- Polytropon >From Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: awk question (actively tail a file & notify when expression is found)
nevermind, i got it to work, with a little help from http://student.northpark.edu/pemente/awk/awk_sys.txt, tail -f /var/log/apache2/access.log | awk '/192.168.1.100/ {system("echo " $0 "| mailx -s test_email m...@email.com" ) }' thx..! 2009/4/22 Bill Campbell : > You might want to look at ``swatch'' which is designed to do > this, and monitors multiple log files simultaneously. > > On Wed, Apr 22, 2009, Evuraan:: wrote: >>Greetings..! >> >>this works, >> >>tail -f /var/log/apache2/access.log | nawk '/192.168.1.100/{ print $0 }' >> >>and this too: >> >> tail -f /var/log/apache2/access.log |awk ' /192.168.1.100/ { system >>("mail -s \"This works\" m...@email.address")}' >> >>but this below, does not work >> >> tail -f /var/log/apache2/access.log |awk ' /192.168.1.100/ { print >>$0 | "mail m...@email.address "}' >> >>Any pointers would be much appreciated. >> >>Thx. >>___ >>freebsd-questions@freebsd.org mailing list >>http://lists.freebsd.org/mailman/listinfo/freebsd-questions >>To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" >> > > -- > Bill > -- > INTERNET: b...@celestial.com Bill Campbell; Celestial Software LLC > URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way > Voice: (206) 236-1676 Mercer Island, WA 98040-0820 > Fax: (206) 232-9186 Skype: jwccsllc (206) 855-5792 > > Capitalism works primarily because most of the ways that a company can be > scum end up being extremely bad for business when there's working > competition. -rra > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" > ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: awk question (actively tail a file & notify when expression is found)
You might want to look at ``swatch'' which is designed to do this, and monitors multiple log files simultaneously. On Wed, Apr 22, 2009, Evuraan:: wrote: >Greetings..! > >this works, > >tail -f /var/log/apache2/access.log | nawk '/192.168.1.100/{ print $0 }' > >and this too: > > tail -f /var/log/apache2/access.log |awk ' /192.168.1.100/ { system >("mail -s \"This works\" m...@email.address")}' > >but this below, does not work > > tail -f /var/log/apache2/access.log |awk ' /192.168.1.100/ { print >$0 | "mail m...@email.address "}' > >Any pointers would be much appreciated. > >Thx. >___ >freebsd-questions@freebsd.org mailing list >http://lists.freebsd.org/mailman/listinfo/freebsd-questions >To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" > -- Bill -- INTERNET: b...@celestial.com Bill Campbell; Celestial Software LLC URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way Voice: (206) 236-1676 Mercer Island, WA 98040-0820 Fax:(206) 232-9186 Skype: jwccsllc (206) 855-5792 Capitalism works primarily because most of the ways that a company can be scum end up being extremely bad for business when there's working competition. -rra ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: awk question
On Thu, 9 Apr 2009 15:32:51 +0200 (CEST), Oliver Fromme wrote: > If ";" is the delimiter character, you need to tell awk > about it (i.e. use the -F option). This one should work: > > awk -F';' '$3 ~ /^[a-z]{5}$/ {print}' file You can even omit {print} because it's the default action (to print the whole line, i. e. $0) when no action is given for a pattern. % awk -F';' '$3 ~ /^[a-z]{5}$/' file When using this in a shell, keep an eye on eventually needed quoting or escaping of $. -- Polytropon >From Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: awk question
Just add a filter NF > 2 to the script. You can even take care of 1 token lines and empty lines in whatever way you wish with other filters. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
"n j" writes: > Or awk only i.e. no sed: > > awk '!(/^$/) { print $(NF-1) }' user.csv That's right. I originally suggested the sed and then was thinking about it as I walked home yesterday and knew that awk could test for the blank line condition before committing suicide.:-) Martin ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
> > > awk '{print $(NF-1)}' user.csv > > Yup, those blank lines will kill it for sure. A sed filter to > remove blank lines ahead of the awk statement should allow it to > work properly. Or awk only i.e. no sed: awk '!(/^$/) { print $(NF-1) }' user.csv -- Nino ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
Don Hinton writes: > On Thursday 26 July 2007 15:26:02 Peter Boosten wrote: > > P.U.Kruppa wrote: > > > > awk '{print $(NF-1)}' user.csv Yup, those blank lines will kill it for sure. A sed filter to remove blank lines ahead of the awk statement should allow it to work properly. Martin McCormick WB5AGZ Stillwater, OK Systems Engineer OSU Information Technology Department Network Operations Group ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
On Thursday 26 July 2007 15:26:02 Peter Boosten wrote: > P.U.Kruppa wrote: > > Hi (and sorry for this slightly OT question), > > > > I would like to extract the second last field of each line of a file > > called user.csv . > > So I try > > > > > awk '{print $(NF-1)}' user.csv > > > > awk: trying to access out of range field -1 > > input record number 1, file user.csv > > source line number 1 > > > > Obviously $(NF-1) doesn't do the trick. Any better idea? > > Hmmm, works for me it does... Me too, except of course if the first line of user.cvs is blank... > > Peter -- Don Hinton or Institute for Software Integrated Systems (ISIS), Vanderbilt University tel: 615.480.5667 or 615.870.9728
Re: awk question
On Thu, 26 Jul 2007, Peter Boosten wrote: P.U.Kruppa wrote: Hi (and sorry for this slightly OT question), I would like to extract the second last field of each line of a file called user.csv . So I try > awk '{print $(NF-1)}' user.csv awk: trying to access out of range field -1 input record number 1, file user.csv source line number 1 Obviously $(NF-1) doesn't do the trick. Any better idea? Hmmm, works for me it does... Sorry: Actually the first line of my user.csv was empty. Thanks though, Uli. Peter -- http://www.boosten.org Peter Ulrich Kruppa Wuppertal Germany ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
P.U.Kruppa wrote: > Hi (and sorry for this slightly OT question), > > I would like to extract the second last field of each line of a file > called user.csv . > So I try > > awk '{print $(NF-1)}' user.csv > awk: trying to access out of range field -1 > input record number 1, file user.csv > source line number 1 > > Obviously $(NF-1) doesn't do the trick. Any better idea? > Hmmm, works for me it does... Peter -- http://www.boosten.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
At 07:43 PM 4/10/2007, Gary Kline wrote: On Tue, Apr 10, 2007 at 06:35:33PM -0500, Derek Ragona wrote: > At 06:17 PM 4/10/2007, Gary Kline wrote: > >On Mon, Apr 09, 2007 at 06:54:07PM -0700, Rick Olson wrote: > >> I'm assuming you've already taken care of this, but to answer your > >> original question in AWK form, you could have done the following: > >> > >> ls -l | awk '$8 == 2006 {system("rm " $9)}' > >> > > > >i'Ll save your snippet to my growing %%% awk file in my ~/HowTo, > >thankee much. I'm in the first stages on a months-long trial on > >system tuning. This, before I'd risk publishing anything. So > >far tho, by upping and lower the NICE prio of various binaries, I > >have been able to get more than 70% efficient use out of my older > >servers. ---This *ought* to carry over to my faster machines > > > >Is tthere a way of using ps -alx | ask to look at nice and if it > >is non-zero (the default), to reset it to zero? > > You can easily do some of this using top, such as: > top -bS 200 | tail -n +9 | awk '{ print $5 }' > > If you want to tweak the nice value you'd need to examine the value and > then renice it as long as you are root. You'd need the PID for that, so > here's another example: > top -bS 200 | tail -n +9 | awk '{ printf("Pid: %d has Nice: %d\n", $1,$5) }' > Well, I knew there had to be a "static" way to read top. -bS is it. If NICE is 9, then renice-n -9 pid ought to reset it to 0; so in C, the check for nice or "n" would be trivial: if (n != 0) n = -n; In you example, would this be if ($1 != 0) $1 = -$1; then a '{system("renice -n $")}; or is this disallowed in awk? gary It is easier to redirect the output to a file then just execute that file. You'd usually have this in a shell script run by cron. top -bS 200 | tail -n +9 | awk '{ if ($1 != 0) printf("/usr/bin/renice %d %d\n", $1,-$5) }' > /tmp/renice.scr sh -c /tmp/renice.scr But look at the file generated, you need to do more than just the check for 0 and then negate it. -Derek -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks transtec Computers for their support. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
On Tue, Apr 10, 2007 at 06:35:33PM -0500, Derek Ragona wrote: > At 06:17 PM 4/10/2007, Gary Kline wrote: > >On Mon, Apr 09, 2007 at 06:54:07PM -0700, Rick Olson wrote: > >> I'm assuming you've already taken care of this, but to answer your > >> original question in AWK form, you could have done the following: > >> > >> ls -l | awk '$8 == 2006 {system("rm " $9)}' > >> > > > >i'Ll save your snippet to my growing %%% awk file in my ~/HowTo, > >thankee much. I'm in the first stages on a months-long trial on > >system tuning. This, before I'd risk publishing anything. So > >far tho, by upping and lower the NICE prio of various binaries, I > >have been able to get more than 70% efficient use out of my older > >servers. ---This *ought* to carry over to my faster machines > > > >Is tthere a way of using ps -alx | ask to look at nice and if it > >is non-zero (the default), to reset it to zero? > > You can easily do some of this using top, such as: > top -bS 200 | tail -n +9 | awk '{ print $5 }' > > If you want to tweak the nice value you'd need to examine the value and > then renice it as long as you are root. You'd need the PID for that, so > here's another example: > top -bS 200 | tail -n +9 | awk '{ printf("Pid: %d has Nice: %d\n", $1,$5) }' > Well, I knew there had to be a "static" way to read top. -bS is it. If NICE is 9, then renice-n -9 pid ought to reset it to 0; so in C, the check for nice or "n" would be trivial: if (n != 0) n = -n; In you example, would this be if ($1 != 0) $1 = -$1; then a '{system("renice -n $")}; or is this disallowed in awk? gary -- Gary Kline [EMAIL PROTECTED] www.thought.org Public Service Unix ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
At 06:17 PM 4/10/2007, Gary Kline wrote: On Mon, Apr 09, 2007 at 06:54:07PM -0700, Rick Olson wrote: > I'm assuming you've already taken care of this, but to answer your > original question in AWK form, you could have done the following: > > ls -l | awk '$8 == 2006 {system("rm " $9)}' > i'Ll save your snippet to my growing %%% awk file in my ~/HowTo, thankee much. I'm in the first stages on a months-long trial on system tuning. This, before I'd risk publishing anything. So far tho, by upping and lower the NICE prio of various binaries, I have been able to get more than 70% efficient use out of my older servers. ---This *ought* to carry over to my faster machines Is tthere a way of using ps -alx | ask to look at nice and if it is non-zero (the default), to reset it to zero? You can easily do some of this using top, such as: top -bS 200 | tail -n +9 | awk '{ print $5 }' If you want to tweak the nice value you'd need to examine the value and then renice it as long as you are root. You'd need the PID for that, so here's another example: top -bS 200 | tail -n +9 | awk '{ printf("Pid: %d has Nice: %d\n", $1,$5) }' -Derek -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks transtec Computers for their support. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
On Mon, Apr 09, 2007 at 06:54:07PM -0700, Rick Olson wrote: > I'm assuming you've already taken care of this, but to answer your > original question in AWK form, you could have done the following: > > ls -l | awk '$8 == 2006 {system("rm " $9)}' > i'Ll save your snippet to my growing %%% awk file in my ~/HowTo, thankee much. I'm in the first stages on a months-long trial on system tuning. This, before I'd risk publishing anything. So far tho, by upping and lower the NICE prio of various binaries, I have been able to get more than 70% efficient use out of my older servers. ---This *ought* to carry over to my faster machines Is tthere a way of using ps -alx | ask to look at nice and if it is non-zero (the default), to reset it to zero? Say that I've reniced xorg and mozilla to -9 for starters and reniced epiphany to -11. Others may have a much lower NICE of 19. I don't know ask that well; is this on better left to something like C? :-) [[[ Something I can do?? :-) ]]] thanks in advance, gary > -- Gary Kline [EMAIL PROTECTED] www.thought.org Public Service Unix ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
You are trying to remove the files whose names are given by ls -lt | awk '{if ($8 == 2006) print $9}'; If you are in the same directory, or you have full pathnames, you can do just (and avoid the 'for do done' loop) rm $( ls -lt | awk '{if ($8 == 2006) print $9}' ) If this exceeds the maximum length of a line, just use xargs also. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
On Tue, Mar 06, 2007 at 07:27:56AM -0600, Derek Ragona wrote: > You can loop through them using a shell script: > for i in `ls -lt | awk '{if ($8 == 2006) print $9}'`;do rm $i;done This is the safest way to rm or rm -i each file ($i); the ls -ls | [awkstuff] spits out the entire list in one chunk. But since packages from 2006 were OLD, I just /bin/rm'd them wholesale. Thanks, gary > > -Derek > > > At 06:35 PM 3/5/2007, Gary Kline wrote: > > >Guys, > > > >Having found $9 , how do I /bin/rm it (using system()--yes??) > >in an awk one-liner? > > > >I'm trying to remove from packages from long ago and find and > >print them with > > > >ls -lt | awk '{if ($8 == 2006) print $9}'; > > > >but what I want to remove the file pointed at by $9. I've tried > >FILE=ARGV[9]; and using FILE within my system() call, but no-joy. > >What's the magic here? > > > >thanks in advance, > > > >gary > > > > > > > >-- > > Gary Kline [EMAIL PROTECTED] www.thought.org Public Service Unix > > > >___ > >freebsd-questions@freebsd.org mailing list > >http://lists.freebsd.org/mailman/listinfo/freebsd-questions > >To unsubscribe, send any mail to > >"[EMAIL PROTECTED]" > > > >-- > >This message has been scanned for viruses and > >dangerous content by MailScanner, and is > >believed to be clean. > >MailScanner thanks transtec Computers for their support. > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > MailScanner thanks transtec Computers for their support. > > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "[EMAIL PROTECTED]" -- Gary Kline [EMAIL PROTECTED] www.thought.org Public Service Unix ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
Gary Kline wrote: Guys, Having found $9 , how do I /bin/rm it (using system()--yes??) in an awk one-liner? I'm trying to remove from packages from long ago and find and print them with ls -lt | awk '{if ($8 == 2006) print $9}'; but what I want to remove the file pointed at by $9. I've tried FILE=ARGV[9]; and using FILE within my system() call, but no-joy. What's the magic here? thanks in advance, gary Another way is: ls -lt | awk '{if ($8 == 2006) print "rm -rf "$9}' | sh but I agree, using pkg_delete would be safer: ls -lt | awk '{if ($8 == 2006) print "pkg_delete "$9}' | sh -SO ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
You can loop through them using a shell script: for i in `ls -lt | awk '{if ($8 == 2006) print $9}'`;do rm $i;done -Derek At 06:35 PM 3/5/2007, Gary Kline wrote: Guys, Having found $9 , how do I /bin/rm it (using system()--yes??) in an awk one-liner? I'm trying to remove from packages from long ago and find and print them with ls -lt | awk '{if ($8 == 2006) print $9}'; but what I want to remove the file pointed at by $9. I've tried FILE=ARGV[9]; and using FILE within my system() call, but no-joy. What's the magic here? thanks in advance, gary -- Gary Kline [EMAIL PROTECTED] www.thought.org Public Service Unix ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]" -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks transtec Computers for their support. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks transtec Computers for their support. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
On Mon, Mar 05, 2007 at 04:46:35PM -0800, Chuck Swiger wrote: > On Mar 5, 2007, at 4:35 PM, Gary Kline wrote: > > Having found $9 , how do I /bin/rm it (using system()--yes??) > > in an awk one-liner? > > I gather that you are looking under /var/db/pkg...? > > >I'm trying to remove from packages from long ago and find and > > print them with > > > > ls -lt | awk '{if ($8 == 2006) print $9}'; > > > > but what I want to remove the file pointed at by $9. I've tried > > FILE=ARGV[9]; and using FILE within my system() call, but no-joy. > > What's the magic here? > > You could pipe the output of awk through "| xargs rm -rf"...but be > careful. > Putting it through "pkg_delete (-f)" might be safer. > Bill and Chuck: These are a slew of packages from 2006. (Obv'ly in /usr/ports/packages. I plumb fergot about xargs (again); just rarely use it. ls -lt | awk Foo catches those that are almost certainly invalid, from '06) but the find -mtime [days] is another way. Like they say about perl, there's always more than one way... When you've got Unix, you've got power at your fingertips. thanks, gents, gary > -- > -Chuck > -- Gary Kline [EMAIL PROTECTED] www.thought.org Public Service Unix ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
On Mar 5, 2007, at 4:35 PM, Gary Kline wrote: Having found $9 , how do I /bin/rm it (using system()--yes??) in an awk one-liner? I gather that you are looking under /var/db/pkg...? I'm trying to remove from packages from long ago and find and print them with ls -lt | awk '{if ($8 == 2006) print $9}'; but what I want to remove the file pointed at by $9. I've tried FILE=ARGV[9]; and using FILE within my system() call, but no-joy. What's the magic here? You could pipe the output of awk through "| xargs rm -rf"...but be careful. Putting it through "pkg_delete (-f)" might be safer. -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
On Mon, Mar 05, 2007, Gary Kline wrote: > > Guys, > > Having found $9 , how do I /bin/rm it (using system()--yes??) > in an awk one-liner? > > I'm trying to remove from packages from long ago and find and > print them with > > ls -lt | awk '{if ($8 == 2006) print $9}'; > > but what I want to remove the file pointed at by $9. I've tried > FILE=ARGV[9]; and using FILE within my system() call, but no-joy. > What's the magic here? A better way to do this might be to use find and xargs. The command below would remove all files under the current directory that haven't been modified in the 360 days. find . -type f -mtime +360 -print0 | xargs -0 rm If you don't want it to go into subdirectories: find . -maxdepth 1 -type f -mtime +360 -print0 | xargs -0 rm Bill -- INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Software LLC URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way FAX:(206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 ``Anyone who thinks Microsoft never does anything truly innovative isn't paying attention to the part of the company that pushes the state of its art: Microsoft's legal department.'' --Ed Foster, InfoWorld Gripe Line columnist ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
Bart Silverstrim wrote: On Mar 6, 2006, at 4:45 PM, Noel Jones wrote: On 3/6/06, Bart Silverstrim <[EMAIL PROTECTED]> wrote: I'm totally drawing a blank on where to start out on this. If I have a list of URLs like http://www.happymountain.com/archive/digest.gif How could I use Awk or Sed to strip everything after the .com? Or is there a "better" way to do it? | cut -d / -f 1-3 Oh boy was that one easy. It was a BAD mental hiccup. I'll add a sort and uniq and it should be all ready to go. Thanks! More than one way to skin that cat! cut is nice'n'easy but since you asked about awk and sed, these would work too: awk -F/ 'NF > 2 {printf "%s//%s\n", $1, $3}' or sed 's,^\([^/]*://[^/]*\).*,\1,' --Alex ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
On Mar 6, 2006, at 4:45 PM, Noel Jones wrote: On 3/6/06, Bart Silverstrim <[EMAIL PROTECTED]> wrote: I'm totally drawing a blank on where to start out on this. If I have a list of URLs like http://www.happymountain.com/archive/digest.gif How could I use Awk or Sed to strip everything after the .com? Or is there a "better" way to do it? I'd like to just pipe the information from the logs to this mini-script and end up with a list of URLs consisting of just the domain (http://www.happymountain.com). | cut -d / -f 1-3 Oh boy was that one easy. It was a BAD mental hiccup. I'll add a sort and uniq and it should be all ready to go. Thanks! ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
On 3/6/06, Bart Silverstrim <[EMAIL PROTECTED]> wrote: > I'm totally drawing a blank on where to start out on this. > > If I have a list of URLs like > http://www.happymountain.com/archive/digest.gif > > How could I use Awk or Sed to strip everything after the .com? Or is > there a "better" way to do it? I'd like to just pipe the information > from the logs to this mini-script and end up with a list of URLs > consisting of just the domain (http://www.happymountain.com). > | cut -d / -f 1-3 -- Noel Jones ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
On 1/20/06, Don Hinton <[EMAIL PROTECTED]> wrote: > > Hi Alexandre: > > On Friday 20 January 2006 16:59, Alexandre Vieira wrote: > > Hello folks, > > > > I'm making a script to generate some statistics for a batch job and I'm > > stuck with awk. > > > > For example: > > > > %echo 1 2 3 4 5 6 | awk {'print $1 $2 $3 $4 $5 $6'} > > > > it will output: > > > > 1 2 3 4 5 6 > > > > I want to tokenize a string with another separating char (the : char): > > > > %echo 1:2:3:4:5:6 > > > > and with awk to output: > > > > 1 2 3 4 5 6 > > > > Is there any way of doing this? > > Sure. Here's a link to the online awk documentation section on field > seperators... > > > http://www.gnu.org/software/gawk/manual/html_node/Field-Separators.html#Field-Separators > > ciao... > don > > > > > > Real example: > > > > I have a log file with the following output: > > 2006-01-20 - 20:01:07 - Some text > > 2006-01-20 - 20:01:15 - Some text > > 2006-01-20 - 20:01:38 - Some text > > (...) > > > > and since I'm generating hourly stats I need to match the "20" which is > in > > a string "20:01:07" that is separated by the char ":". > > > > I hope I've been clear. > > > > Thanks for your help. > > ___ > > freebsd-questions@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > > To unsubscribe, send any mail to > > "[EMAIL PROTECTED]" > > -- > Don Hinton tel: 615.480.5667 > ISIS, Vanderbilt University skype: donhinton > http://people.vanderbilt.edu/~don.hinton/ > > > Geez I can believe it was that easy. Thank you. -- Alexandre Vieira - [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question
Hi Alexandre: On Friday 20 January 2006 16:59, Alexandre Vieira wrote: > Hello folks, > > I'm making a script to generate some statistics for a batch job and I'm > stuck with awk. > > For example: > > %echo 1 2 3 4 5 6 | awk {'print $1 $2 $3 $4 $5 $6'} > > it will output: > > 1 2 3 4 5 6 > > I want to tokenize a string with another separating char (the : char): > > %echo 1:2:3:4:5:6 > > and with awk to output: > > 1 2 3 4 5 6 > > Is there any way of doing this? Sure. Here's a link to the online awk documentation section on field seperators... http://www.gnu.org/software/gawk/manual/html_node/Field-Separators.html#Field-Separators ciao... don > > Real example: > > I have a log file with the following output: > 2006-01-20 - 20:01:07 - Some text > 2006-01-20 - 20:01:15 - Some text > 2006-01-20 - 20:01:38 - Some text > (...) > > and since I'm generating hourly stats I need to match the "20" which is in > a string "20:01:07" that is separated by the char ":". > > I hope I've been clear. > > Thanks for your help. > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "[EMAIL PROTECTED]" -- Don Hinton tel: 615.480.5667 ISIS, Vanderbilt University skype: donhinton http://people.vanderbilt.edu/~don.hinton/ pgpMuZXJJHZeq.pgp Description: PGP signature
Re: awk question, maybe
# [EMAIL PROTECTED] / 2003-12-15 16:30:33 -0700: > i would like to do something like > > df | awk '{print $1}' > > to capture all the current file systems. But I would like to strip > off the first and last lines, since these are generally -- not needed. > > the goal is to write a generalized script that can feed dump with all > the file systems on a box. I would use mount(8) instead: its output doesn't include any headers, but you'll still want to pass through only local filesystems, so it doesn't really matter: [EMAIL PROTECTED] ~ 1006:0 > mount | awk '/\/dev\/(ad|da)/ {print $1}' /dev/ad0s1a /dev/ad0s1e [EMAIL PROTECTED] ~ 1007:0 > df | awk '/\/dev\/(ad|da)/ {print $1}' /dev/ad0s1a /dev/ad0s1e -- If you cc me or remove the list(s) completely I'll most likely ignore your message.see http://www.eyrie.org./~eagle/faqs/questions.html ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question, maybe
man head and man tail At 05:30 PM 12/15/2003, you wrote: i would like to do something like df | awk '{print $1}' to capture all the current file systems. But I would like to strip off the first and last lines, since these are generally -- not needed. the goal is to write a generalized script that can feed dump with all the file systems on a box. any pointers? -- David Bear phone: 480-965-8257 fax:480-965-9189 College of Public Programs/ASU Wilson Hall 232 Tempe, AZ 85287-0803 "Beware the IP portfolio, everyone will be suspect of trespassing" ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]" --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.545 / Virus Database: 339 - Release Date: 11/27/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.545 / Virus Database: 339 - Release Date: 11/27/2003 ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question, maybe
On Mon, Dec 15, 2003 at 08:39:06PM -0300, Fernando Gleiser wrote: > On Mon, 15 Dec 2003, David Bear wrote: > > > i would like to do something like > > > > df | awk '{print $1}' > > > > to capture all the current file systems. But I would like to strip > > off the first and last lines, since these are generally -- not needed. > > df | awk '$1 ~/^\/dev/ {print $1}' > yes.. I was hoping it would be simple. and I thought of using a regex to match the lines I want after sending that note. thanks for all the replies. -- David Bear phone: 480-965-8257 fax:480-965-9189 College of Public Programs/ASU Wilson Hall 232 Tempe, AZ 85287-0803 "Beware the IP portfolio, everyone will be suspect of trespassing" ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: awk question, maybe
On Mon, 15 Dec 2003, David Bear wrote: > i would like to do something like > > df | awk '{print $1}' > > to capture all the current file systems. But I would like to strip > off the first and last lines, since these are generally -- not needed. df | awk '$1 ~/^\/dev/ {print $1}' Fer ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"