Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Want to split awk command

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-29-2013   -   Original Discussion by Sanket Dalvi
Sanket Dalvi Sanket Dalvi is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 6 July 2013, 11:15 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Want to split awk command

Hi,
There is an awk command in script and it is running successfully.
I want to split that command in 2 lines.
I have tried using '\' but its not working..
Please suggest me the solution.
Sponsored Links
    #2  
Old Unix and Linux 06-29-2013   -   Original Discussion by Sanket Dalvi
mjf mjf is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 29 January 2017, 12:48 PM EST
Location: Newtown, PA
Posts: 172
Thanks: 12
Thanked 49 Times in 45 Posts
Are you ending the line(s) with a backslash surrounded by single quotes (e.g. '\' ) instead of just the backslash (e.g. \)? It's impossible to tell what you did without seeing your code.
Sponsored Links
    #3  
Old Unix and Linux 06-29-2013   -   Original Discussion by Sanket Dalvi
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 19 November 2017, 11:06 AM EST
Location: Galactic Empire
Posts: 3,601
Thanks: 253
Thanked 1,315 Times in 1,232 Posts
Please note that backslash continuation does not work with C shell. It works for awk program files if you are using a POSIX compliant shell.

If you want to get it work on C shell, follow the instructions specified here
    #4  
Old Unix and Linux 06-30-2013   -   Original Discussion by Sanket Dalvi
Sanket Dalvi Sanket Dalvi is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 6 July 2013, 11:15 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hi ,
I am using only \ and not the '\'.
Definately i will share the code soon...
thanks for your response.
Sponsored Links
    #5  
Old Unix and Linux 07-01-2013   -   Original Discussion by Sanket Dalvi
Sanket Dalvi Sanket Dalvi is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 6 July 2013, 11:15 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,
Below is the command which i want to split
Code:
Hi, 
awk -F"\t" '{printf "%-1s;%-12s;%-2s;%-12s;%-12s;%-1s;%-12s;%-6s;%-12s;%-4s; 
%-12s;%-20s;%-8s;%-3s;%-11s;%-6s;%-15s;%-11s;%-105s;%-70s;%-35s;%-35s;%-35s;%-35s;%-35s;%-35s;%-90s;%-15s;%-70s;%-2s;%-10s;%-4s;%-4s;%-35s;%-60s;%-12s;%-12s;%-35s;%-70s;\n",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39}' san

Where san is the file name
Thanks in Advance
Sponsored Links
    #6  
Old Unix and Linux 07-01-2013   -   Original Discussion by Sanket Dalvi
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 19 November 2017, 11:06 AM EST
Location: Galactic Empire
Posts: 3,601
Thanks: 253
Thanked 1,315 Times in 1,232 Posts
Copy, paste and run below code:

Code:
awk -F"\t" '
{
printf "%-1s;%-12s;%-2s;%-12s;%-12s;%-1s;%-12s;%-6s;%-12s;%-4s;%-12s;%-20s;%-8s; \
        %-3s;%-11s;%-6s;%-15s;%-11s;%-105s;%-70s;%-35s;%-35s;%-35s;%-35s;%-35s;%-35s; \
        %-90s;%-15s;%-70s;%-2s;%-10s;%-4s;%-4s;%-35s;%-60s;%-12s;%-12s;%-35s;%-70s;\n", \
        $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,\
        $14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26, \
        $27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39;
} ' san

Sponsored Links
    #7  
Old Unix and Linux 07-01-2013   -   Original Discussion by Sanket Dalvi
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 19 November 2017, 7:13 AM EST
Location: San Jose, CA, USA
Posts: 10,658
Thanks: 571
Thanked 3,733 Times in 3,185 Posts
I think you'll find that Yoda's suggestion add lots of additional spaces to the output at the line breaks in his code. I think the following will do what you want:

Code:
awk -F"\t" '{printf "%-1s;%-12s;%-2s;%-12s;%-12s;%-1s;%-12s;%-6s;%-12s;" \
    "%-4s;%-12s;%-20s;%-8s;%-3s;%-11s;%-6s;%-15s;%-11s;%-105s;%-70s;%-35s;" \
    "%-35s;%-35s;%-35s;%-35s;%-35s;%-90s;%-15s;%-70s;%-2s;%-10s;%-4s;%-4s;" \
    "%-35s;%-60s;%-12s;%-12s;%-35s;%-70s;\n",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,
    $11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,
    $30,$31,$32,$33,$34,$35,$36,$37,$38,$39}' san

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk to split one field and print the last two fields within the split part. yifangt Shell Programming and Scripting 5 04-17-2012 05:41 AM
Split a file using awk command. guptam Shell Programming and Scripting 7 04-04-2012 12:13 PM
using awk in perl with split command vineet.dhingra Shell Programming and Scripting 9 01-03-2012 03:44 AM
Awk command to split file name mskalyani9 Shell Programming and Scripting 10 11-04-2010 05:45 AM
awk command to split in to 2 files m_subra_mani Shell Programming and Scripting 3 12-13-2005 05:13 PM



All times are GMT -4. The time now is 12:10 PM.