Tue, 22 Apr 2003
One-liner shell scripts

I needed to back-date a bunch of files at work. Each file had a date in it like "Apr 4" or "Apr 23"; the back-dating had to match that date.

I ended up with two one-line shell scripts like the following:
for i in *.txt ; do j=`awk 'BEGIN { do { l = getline; match($0, /Apr [0-9],/) ; s = substr($0,RSTART+4,RLENGTH-5) } while ((s !~ /[0-9]/) && (l !=0)) ; print s ; close(l)}' $i` ; if [[ $j == [0-9] ]] ; then k=`echo "2003040 $j 1100" | sed 's/ //g'` ; touch -t $k $i ; fi ;done
(The other matched for two digits before the comma.)

I decided to do this as a shell-and-awk script because I thought doing it in perl would be too complicated. :-P

Archives:
April 2018
S
M
T
W
T
F
S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Mar     May


Search this blog:
Search the blogs I read:
www.flickr.com
Taper Wickel's photos More of Taper Wickel's photos