Need sed-one-liner decoded please.

This is a discussion on Need sed-one-liner decoded please. within the awk forums in Programming Languages category; I was complaining about non-maintainable, code and the task that I gave as an example to do was:- | rearrange a small text file, so that: | * all lines of length > 78 are wrapped to len < 75, with breaks at | word-boundries; | * the "> " strings which start each line are replaced to the | beginning of the new shorter lines; And some smart-arse gave:- >this tiny task simply cries out for a "one-liner" shell script! > > sed -s 's/^> //' ${1+"$@"} | fmt -75 | sed -s 's/^/> /' Here's my attempt at ...

Go Back   Application Development Forum > Programming Languages > awk

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-21-2008, 07:58 AM
problems@gmail
Guest
 
Default Need sed-one-liner decoded please.

I was complaining about non-maintainable, code and the
task that I gave as an example to do was:-
| rearrange a small text file, so that:
| * all lines of length > 78 are wrapped to len < 75, with breaks at
| word-boundries;
| * the "> " strings which start each line are replaced to the
| beginning of the new shorter lines;

And some smart-arse gave:-

>this tiny task simply cries out for a "one-liner" shell script!
>
> sed -s 's/^> //' ${1+"$@"} | fmt -75 | sed -s 's/^/> /'


Here's my attempt at starting to decode this:

| fmt -75 |
Means 'accept the stream and format it into line-len < 76 and pass it on'

sed -s 's/^> //' = dud !?

sed s 's/^> //' = substitute: newLine, ">" with nil == fails
---------
Here's my well commented code so far.
The failing part is replacing char(10) with a space.
Probably since sed reads one LINE at a time ?
I'm aware of potential 'overflow' if it's all one line.
--------------
# remove all leading ">" ==
sed s/^">"//g DataFl > Rm1stArw.1

# replace \n with space
#sed s/$/"x"/g Rm1stArw.1 > RmLT.2
#sed s/\n/" "/g Rm1stArw.1 > RmLT.2
#sed s/$/" "/g Rm1stArw.1 > RmLT.2
#sed s/$\n/" "/g Rm1stArw.1 > RmLT.2
#sed '$!N;s/\n/" "/' Rm1stArw.1 > RmLT.2
# sed '$!N;s/\n/ /' Rm1stArw.1 > RmLT.2 ==ok every 2nd line was joined
#sed 's/\n/ /g' Rm1stArw.1 > RmLT.2
sed 's/\n/ /'g Rm1stArw.1 > RmLT.2 <-- last try also fails !

cat RmLT.2 | fmt -44 > Linewrap.3

#and remove leading space from fmt ?
# try: [ \t]* ==[Spc and?or Tab]Repeated
sed s/^" "// Linewrap.3 > NoLdSpc.4

# add leading ">"
sed s/^/">"/ NoLdSpc.4 > Done
----------------- end of script

== TIA.

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:41 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.