On 28 Mar 2004 14:15:11 -0800
[email]sura_12@yahoo.com[/email] (Raja) wrote:
> Why is my program not working?
Did you perchance forget to sacrifice a chicken? You need
to do that if you want to get perls out of awk ;-)
> Earlier the data file was delimited
> with "|"(Pipe) and the program worked. But now we changed the
> delimiter to X and a backspace character.
What an utterly weird idea. Do you absolutely have to do that?
> I have tried this by
> replacing the "|" in my programm as follows and it does not work. Any
> help would be greatly appreciated.
\b works in Perl, not in awk. Make sure your backspace
has been correctly entered in the script, and isn't a
sequence of two characters, which is why I suggest putting
it in a file, rather than inline:

$ cat stuff.awk
BEGIN { FS = "X^H" }
{
if ( NF < 6 ){
newline=$0
oldline = newline
getline
newline = substr(oldline,1,length(oldline))";" $0
while (substr(newline,length(newline),1) != "X^H"){
oldline = newline
getline
newline = substr(oldline,1,length(oldline))";" $0
}
print newline
next
}
else print $0
}

$ awk -f stuff.awk test.txt

If you're using vi, the sequence control-V control-H will generate
a backspace (010) character, represented by the sequence ^H.

Note that "awk" on Solaris (but not "nawk") will consider any X not
followed by a backspace as a separator. Don't use awk when you're
on a Solaris box.

Take care,

--
Stefaan
--
"What is stated clearly conceives easily." -- Inspired sales droid