Want to unwrap lines in a text file unix best solution needed.
Hey there,
I want to unwrap lines in a text file Unix formatted. I've tried several different software but didn't get the expected resulted. So I want the best solution for this.
Hey there,
I want to unwrap lines in a text file Unix formatted. I've tried several different software but didn't get the expected resulted. So I want the best solution for this.
Hi Walter,
In order to unwrap lines in your unix text file (input.txt), you need to create the text file : unwordwrap.awk that contains the following :
#!/usr/bin/gawk
BEGIN {RS="nn"; FS="n"}
{for (i=1;i<=NF;i++) printf $i" ";Â printf "nn" }
Â
Then run it using : awk -f unwordwrap.awk < input.txt
Â
And here after is the explanation of the code in unwordwrap.awk file:
BEGIN {RS="nn"; FS="n"}
Defines the record separator (RS) to be two newlines (this is one newline by default, but we want to grab records that are 'anything between two newlines'), and defines the field separator (FS) to be a single newline (this is usually any run of one or more whitespace characters, but we want a field to be a whole line).
for (i=1;i<=NF;i++) printf $i" "
Runs through each field (a line in our case) in each record (the bits between the blank lines), and prints the field with no newline after it, joining the split lines back up.
printf "nn"
Prints a double newline to get your blank line after each line in the output.
Â
Best Regards.
Â