LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-05-2011, 10:53 AM   #1
crxlurp
LQ Newbie
 
Registered: Jul 2011
Posts: 14

Rep: Reputation: Disabled
awk script to filter and delete


Hey guys! First off, thanks for any help you can provide me. I am trying to figure out how to write an awk script(or something better if it exists) to read a text file that contains lines like below.

4517-s-1295546289-10:58:09-2011-01-20.wav | 19990 KiB | 2940.5 KiB/s | binary | 100%
4517-s-1303247233-15:07:13-2011-04-19.wav | 167 KiB | 2918.3 KiB/s | binary | 100%
4517-s-1301431748-14:49:08-2011-03-29.wav | 36220 KiB | 2589.3 KiB/s | binary | 100%
4517-s-1295974735-09:58:55-2011-01-25.wav | 20038 KiB | 2646.0 KiB/s | binary | 100%
4517-s-1295648478-15:21:18-2011-01-21.wav | 45561 KiB | 2154.1 KiB/s | binary | 100%
4517-s-1300384178-11:49:38-2011-03-17.wav | 6752 KiB | 2216.0 KiB/s | binary | 100%

I want to find lines that start with 4517-s and end with 100% and delete them from a directory.

I am sorry, I just am too new to know where to even start.
 
Old 07-05-2011, 11:02 AM   #2
crxlurp
LQ Newbie
 
Registered: Jul 2011
Posts: 14

Original Poster
Rep: Reputation: Disabled
Also, I am not sure if I have posted this in the wrong place or not so if I have, please let me know and I will move it.
Thanks
 
Old 07-05-2011, 12:00 PM   #3
aysheaia
LQ Newbie
 
Registered: Jun 2011
Distribution: Ubuntu
Posts: 26

Rep: Reputation: Disabled
For example (with a) input file named list.in, b) no spaces in any wav files, c) directory where to delete files located in current directory and named sound) :
Code:
$ dir=sound
$ awk -vDIR=$dir ' /^4517.*100%$/ { system("rm "DIR"/"$1) } ' list.in
 
Old 07-05-2011, 12:13 PM   #4
crxlurp
LQ Newbie
 
Registered: Jul 2011
Posts: 14

Original Poster
Rep: Reputation: Disabled
First off thanks for your help. After looking at my file, I noticed that I can just go ahead and delete all files ending in 100% so I think I can just write this:

Code:
dir=/var/spool/asterisk/monitor
awk -vDIR=$dir ' /*100%$/ { system("rm "DIR"/"$1) } ' output.txt
is that correct?
 
Old 07-05-2011, 12:43 PM   #5
aysheaia
LQ Newbie
 
Registered: Jun 2011
Distribution: Ubuntu
Posts: 26

Rep: Reputation: Disabled
Quote:
Originally Posted by crxlurp View Post
Code:
dir=/var/spool/asterisk/monitor
awk -vDIR=$dir ' /*100%$/ { system("rm "DIR"/"$1) } ' output.txt
is that correct?
No, you must put a dot before the star :
Code:
$ awk -vDIR=$dir ' /.*100%$/ { system("rm "DIR"/"$1) } ' output.txt
In a regular expression (regexp), dot means any single character and star means that the previous regexp can be repeated 0 to n times (and dollar means the end of record).
See awk regexp at http://www.gnu.org/software/gawk/man...wk.html#Regexp
 
Old 07-05-2011, 01:23 PM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Actually, you don't need the dot and star at all. This will work:

Code:
/100%$/
 
Old 07-05-2011, 01:33 PM   #7
crxlurp
LQ Newbie
 
Registered: Jul 2011
Posts: 14

Original Poster
Rep: Reputation: Disabled
closing. Please look at http://www.linuxquestions.org/questi...pt-890051-new/

sorry for duplicate.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 09:06 PM
[SOLVED] Problems to exclude lines and bad filter within AWK script cgcamal Programming 7 04-30-2010 12:38 AM
Using sed or awk to filter a file mitchell2345 Linux - Software 3 04-10-2009 10:07 AM
delete/filter parts of file belbono Linux - Newbie 5 02-25-2009 01:04 PM
Delete lines using awk kkjegan Programming 13 09-11-2007 07:36 PM


All times are GMT -5. The time now is 01:04 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration