Linux commands, scripts, tools and systems administration

--> a use-of-awk.txt
##################################################################################################################################

PROBLEM:  needed to remove a series of images that were defective,
they were all less than 10k in size, but only on certain days... 
so a long listing was saved to a file, "fix".  Then the file "fix"
was edited using vi and all entries below the last date were deleted.

The contents of fix were displayed with the cat command.  One could
edit the file to remove the permissions, owner, size and date information,
or use AWK to print only what was needed.  

But running awk only sends the output to stdout... does NOT execute the commands. 
An intermediate file is used, and then executed as a shell script.  Remember to delete
these temporary working files.

------------------------------------------------
ls -al > fix
------------------------------------------------

--> cat fix
-rw-r--r--  1 fotos fotos     7252 Oct  6 20:40 20130102_064001_00.jpg
-rw-r--r--  1 fotos fotos     7572 Oct  6 20:41 20130102_064501_00.jpg
	....
-rw-------  1 fotos fotos     6436 Oct  9 18:32 20130105_065501_00.jpg
-rw-------  1 fotos fotos     9028 Oct  9 18:32 20130105_070001_00.jpg
------------------------------------------------

--> cat fix | awk '{print "rm -f "$9}'
rm -f 20130102_064001_00.jpg
rm -f 20130102_064501_00.jpg
...
rm -f 20130105_065501_00.jpg
rm -f 20130105_070001_00.jpg

------------------------------------------------
--> cat fix | awk '{print "rm -f "$9}' > fixnow
------------------------------------------------
--> sh ./fixnow
------------------------------------------------
--> rm -f fix fixnow
------------------------------------------------
##################################################################################################################################
this is only one of several ways of solving this problem, awk could be used with ls to bypass a step, e.g.:

 -> ls -al |  awk '{print $5 " "$9 }' | sort > files

vi files - remove files that you WANT, then cat files again, using awk to get the 2nd field and replace with "rm -f", e.g.
(test the process without the redirect FIRST to see if the files are listed with rm -f in front, if so, complete string...)

cat files | awk '{print "rm -f " $2}' > nukem-files ; sh ./nukem-files ; rm -f nukem-files  
##################################################################################################################################

SEARCH and Navigation TOOL
Google     select a domain to search or visit.
(use back key to return )

johnmeister.com/jeep/sj
JeepMeister
"Jeep is America's
only real sports car."
-Enzo Ferrari
JohnMeister.com LinuxMeister
MeisterTech FotoMeister.us
BibleTech the rest of the web
books: Linux or UNIX
selected books, bottom of page...
Computers:

For the best synthetic lubricants, filters, and other automotive products use the free AMSOIL product guide - SELECT: year, make and model.

visit AMSOIL's site, or call 1-800-956-5695,
please use customer #283461

Buy AMSOIL at Northland Diesel in Bellingham, WA

Diesel Engines --- BioDiesel info --- Tools --- Automotive Repair Books

assorted links
Everett weather -- traffic --- News -- NASB/KJV -- Middle East
South East Asian Missions -- BibleTech -- Voice of the Martyrs

Nuts-Bolts-Wrench specs

recommended books: (these books are on my shelf, enjoyed them, know the author, contributed something to them, have taught using them, or found them to be the best available)...