Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I personally don't think sed it the way to go here. All you seem to be doing is moving text, not manupilating it much.
I haven't used awk much, so I don't have an opinion here. But a small shell or perl script would do the job quite easily. All you have to do i read a few lines at the time, store the lines or tokens in variables, and the write the stored variables to a file.
If you don't mind preprocessing w/ sed, this is pretty short & sweet:
Code:
#! /bin/bash
cat $1 \
| sed -r 's,^out: *([^ ]*),@\1\n,
/^in/N;s,^in: *([^ ]+).*\n,\1\n@,' \
| awk 'BEGIN{RS=""; FS="\n@"};
{print "@","\n"$1,$3,"\n"$2}'
exit # end of script
## test output:
@
160.11 165.02
See our bus? It's really big.
@
165.12 171.03
-Is it the great big one here?
-That's right.
I might add this is the 1st time I have seen a perl script of <100 lines that is shorter than my bash equivalent.
EDIT:
I spoke too soon -- here is an all sed script that is the shortest of all:
Code:
#!/bin/sed -rf
:n;N;s,out: *,@,;T n
s,in: *([^\n]*)(.*)\n@(.*),@\n\1 \3\2,
I don't know if this is good or bad -- we can only guess at the true format of the actual data -- but I don't assume that the "in:" & "out:" data will be digits. I could if needed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.