![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
sed challange
This forum is near death. Maybe some interesting activity will restore it to life.
Challenge - write a simple sed script to reverse a string or file: prompt$> echo "hi there" | sed 'your script goes here' ereht ih ie. the behavior should match the rev command utility. I'll post an answer on Friday.... |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
I'd like to see more entries in this section also... maybe a weekly script challenge or something.
#!/usr/bin/sed -f # reverse all chars of each line, keep line ordering # ignore empty lines, i.e. nothing to reverse /./!b # escape ! by doubling it, place markers at beginning and end of line # the markers are -!- which can never happen after the escaping of ! s/!/!!/g s/^/-!-/ s/$/-!-/ # swaps first char after first maker, with first char before last marker # and then advance the markers through the swapped chars ta :a s/-!-\([^!]\|!!\)\(.*\)\([^!]\|!!\)-!-/\3-!-\2-!-\1/ ta # delete markers, and then unescape the !s s/-!-//g s/!!/!/g ir@grendel [~/code/sed]# echo "hi there" | ./s.sh ereht ih
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
I came up with:
sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//' |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Heres the challange | John07 | Visual Basic | 3 | Jan 21st, 2005 11:31 AM |