![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| AWK doubt | Rafael.Buria | Shell Programming and Scripting | 2 | 02-06-2008 11:00 AM |
| doubt about awk | soujanya_srk | UNIX for Dummies Questions & Answers | 2 | 01-10-2008 05:26 PM |
| SDL doubt | royalibrahim | High Level Programming | 0 | 11-22-2007 01:49 AM |
| awk doubt.. | esham | Shell Programming and Scripting | 11 | 10-11-2007 02:24 AM |
| ftp doubt | ranj@chn | Shell Programming and Scripting | 0 | 01-04-2006 08:47 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 |
|
||||
|
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
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|