I'll be honest, I was a UNIX guy long ago, but that has fallen into a
void due to years of non-use. I don't know what to do and need a
little help from you guys.
I need an input file to be formatted with awk (or another utility) as
per these examples:
http://chocolatine.org/eric/input.txt
http://chocolatine.org/eric/output.txt
So yeah. Got any scripts to take input.txt, and come out with
output.txt?
Thanks in advance!
Eric
awk '
/^[^[:space:]]/{
if(last""){
print last"; "r;s=""
}
last=$1"; "
sub(/^[^[:space:]]+[[:space:]]+/,"")
r=$0;next
}
{sub(/^[[:space:]]+[^[:space:]]+[[:space:]]+/,"");last=last s $0;s=", "}
END{if(last""){print last"; "r}}' file.txt
assuming the first field in the line never contains spaces.
On 2009-04-21, eric...@gmail.com <eric...@gmail.com> wrote:
> [...]
> I need an input file to be formatted with awk (or another utility) as
> per these examples:
>
> http://chocolatine.org/eric/input.txt
>
> http://chocolatine.org/eric/output.txt
>
> So yeah. Got any scripts to take input.txt, and come out with
> output.txt?
> [...]
Hi,
a tested script for this task. It should work with any new awk.
- --------------------------8<--------------------------------
substr($0,1,1) ~ /[ \t]/ {
printf "%s %s", (prev_hdr ? ";" : ","), flds_from(2)
prev_hdr = 0
next
}
NR > 1 {
printf "; %s\n\n", hdr2
}
{
printf "%s", $1
hdr2 = flds_from(2)
prev_hdr = 1
}
END {
printf "; %s\n", hdr2
}
function flds_from(start, s, i)
{
for (i = start; i <= NF; ++i)
s = s (i == start ? "" : " ") $i
return s
}
- --------------------------8<--------------------------------
call it:
awk -f scriptfile input.txt >output.txt
Kind regards,
Steffen
- --
Steffen Schuler (goedel) <schuler...@gmail.com>
Key ID: 0x42C5D853 / Key-server: pgp.mit.edu
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAknuHyAACgkQ+/TWb0LF2FMlBQCdFQ2HaNUyvxd01+eruLy7T4jN
NskAn3zv/TORyRIrwBFdevxxFOa4e+RR
=+iXI
-----END PGP SIGNATURE-----