help with delete script
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. |
I have gone over my output.txt file that I will be reading and it looks like I can just delete any file whose line ends in 100% Not sure if that makes things easier or not.
|
Quote:
I'd grep the text file first, and look for anything with "100%", then read that and pipe it into rm. Of course, you should back up your data first, whenever you're doing something that deletes files. Read the man pages for grep and awk, and read one of the THOUSANDS of bash scripting tutorials you can find with Google. This: Code:
rm `grep "100\%" <filename> | awk {'print $1'}` |
grep 100% file.txt | cut -d\ -f1 | xargs rm -f
|
Or, if you want to do it in gawk, gawk -F'|' '/^4517.*100%$/{print "rm -f " $1}' input_text_file_name should print out all the remove commands (for QA check), and replacing the print "rm -f " $1 with a system("rm -f " $1) should run it.
Note: Untested code. |
Quote:
This is the command I ran. Code:
gawk -F'|' '/.*100%$/{print "rm -f " $1}' output.txt |
Quote:
|
Quote:
|
This is a duplicate thread:
http://www.linuxquestions.org/questi...delete-890037/ Anyway, the "cut" command gets rid of everything after the first space character on every line, and the "xargs" command splits the input into separate strings using whitespce as the delimiter, and then passes them as arguments to rm. |
Yes, sorry about the duplicate thread. I need to delete the newbie one. I don't think that was the right place to put it. anyway, could I run grep 100% file.txt | cut -d\ -f1 | xargs rm -f without the delete and have it output what it finds and cuts?
|
Quote:
|
when I run
Code:
grep 100% output.txt | cut -d\ -f1 | echo Code:
cut: the delimiter must be a single character |
!
Quote:
|
Quote:
Code:
cut -d' ' -f1 |
when I run
Code:
grep 100% output.txt | cut -d" " -f1 | echo Beginning of file C:\Data\bkup\recording>cd\ C:\>cd data C:\Data>cd Shared C:\Data\Shared>cd "10-Recording Archive" C:\Data\Shared\10-Recording Archive>cd 4511 C:\Data\Shared\10-Recording Archive\4511>winscp /script=C:\Data\bkup\recording\recordingftp4511.script batch on confirm off Searching for host... Connecting to host... Authenticating... Using username "admin". Authenticating with pre-entered password. Authenticated. Starting the session... Reading remote directory... Session started. Active session: [1] admin@192.168.90.15 /var/spool/asterisk/monitor transfer binary 4511-s-1295472704-14:31:44-2011-01-19.wav | 165 KiB | 3446.4 KiB/s | binary | 100% 4511-s-1299187431-14:23:51-2011-03-03.wav | 153 KiB | 2521.2 KiB/s | binary | 100% 4511-s-1295539212-09:00:12-2011-01-20.wav | 8472 KiB | 2975.7 KiB/s | binary | 100% Session 'admin@192.168.90.15' closed. No session. C:\Data\Shared\10-Recording Archive\4511>cd .. C:\Data\Shared\10-Recording Archive>cd 4513 C:\Data\Shared\10-Recording Archive\4513>winscp /script=C:\Data\bkup\recording\recordingftp4513.script batch on confirm off Searching for host... Connecting to host... Authenticating... Using username "admin". Authenticating with pre-entered password. Authenticated. Starting the session... Reading remote directory... Session started. Active session: [1] admin@192.168.90.15 /var/spool/asterisk/monitor transfer binary Session 'admin@192.168.90.15' closed. This is the end of the snippet of file This goes on for hundreds of lines, but essentially the same thing repeating. |
All times are GMT -5. The time now is 07:04 AM. |