![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| AWK doubt | Rafael.Buria | Shell Programming and Scripting | 2 | 02-06-2008 07:00 AM |
| doubt about awk | soujanya_srk | UNIX for Dummies Questions & Answers | 2 | 01-10-2008 01:26 PM |
| SDL doubt | royalibrahim | High Level Programming | 0 | 11-21-2007 09:49 PM |
| awk doubt.. | esham | Shell Programming and Scripting | 11 | 10-10-2007 11:24 PM |
| ftp doubt | ranj@chn | Shell Programming and Scripting | 0 | 01-04-2006 04:47 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi ,
I have a file in the below format: 1.txt awk 'BEGIN { printf ("%1s", "man" )} ' awk 'BEGIN { printf ("%9s", "women" )} ' awk 'BEGIN { printf ("%56s", "human")} ' ## ### ## echo "$!" ## awk 'BEGIN { printf ("%1s", "aaa" )} ' awk 'BEGIN { printf ("%19s", "bbb" )} ' awk 'BEGIN { printf ("%24s", "ccc" )} ' ### # ## awk 'BEGIN { printf ("%1s", "rrr"} ' awk 'BEGIN { printf ("%31s", "ddd"}' awk 'BEGIN { printf ("%43s","eeee"}' I want to convert it to the below file: 2.txt awk 'BEGIN { printf ("%1s", "man" ); printf ("%9s", "women" ); printf ("%56s", "human")}' ## ### ## echo "$!" ## awk 'BEGIN { printf ("%1s", "aaa"); printf ("%19s", "bbb"); printf ("%24s","ccc" )}' ### # ## awk 'BEGIN { printf ("%1s", "rrr"); printf ("%19s", "ddd"); printf ("%24s","eeee")}' Can this be done? Thanks in advance JS |
| Forum Sponsor | ||
|
|
|
|||
|
Hi Johnson ,
I got the out as below : awk ' BEGIN { printf ("%1s", "man" ) awk 'BEGIN { printf ("%1s", "man" )} ' printf ("%9s", "women" ) awk 'BEGIN { printf ("%9s", "women" )} ' printf ("%56s", "human") awk 'BEGIN { printf ("%56s", "human")} ' }' echo "$!" awk ' BEGIN { printf ("%1s", "aaa" ) awk 'BEGIN { printf ("%1s", "aaa" )} ' printf ("%19s", "bbb" ) awk 'BEGIN { printf ("%19s", "bbb" )} ' printf ("%24s", "ccc" ) awk 'BEGIN { printf ("%24s", "ccc" )} ' }' echo "$!" awk ' BEGIN { printf ("%1s", "rrr") awk 'BEGIN { printf ("%1s", "rrr")} ' printf ("%31s", "ddd") awk 'BEGIN { printf ("%31s", "ddd")}' printf ("%43s","eeee") awk 'BEGIN { printf ("%43s","eeee")}' }' }' Am trying to tune the code a bit so tat I can reach to the required o/p Thanks a lot for ur time JS |
|
|||
|
This puts the closing quote on a separate line, maybe that's acceptable?
Code:
awk -v sq="'" '
{ if (/^awk .BEGIN { /){
if (prev) gsub("awk " sq "BEGIN", "");
gsub ("} *" sq, "}");
prev = 1;
} else {
if (prev) printf ("%c\n", sq);
prev = 0;
}
print }
END { if (prev) printf "%c\n", sq }' 1.txt
|
|||
| Google UNIX.COM |