Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Want to split awk command

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-29-2013
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
mjf mjf is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 26 April 2015, 8:17 PM EDT
Location: Newtown, PA
Posts: 151
Thanks: 9
Thanked 37 Times in 35 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
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 20 April 2015, 6:16 PM EDT
Location: Galactic Empire
Posts: 3,402
Thanks: 240
Thanked 1,216 Times in 1,142 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-29-2013
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
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
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 20 April 2015, 6:16 PM EDT
Location: Galactic Empire
Posts: 3,402
Thanks: 240
Thanked 1,216 Times in 1,142 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
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 27 April 2015, 2:29 AM EDT
Location: San Jose, CA, USA
Posts: 6,150
Thanks: 249
Thanked 2,040 Times in 1,744 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 04:41 AM
Split a file using awk command. guptam Shell Programming and Scripting 7 04-04-2012 11:13 AM
using awk in perl with split command vineet.dhingra Shell Programming and Scripting 9 01-03-2012 02:44 AM
Awk command to split file name mskalyani9 Shell Programming and Scripting 10 11-04-2010 04:45 AM
awk command to split in to 2 files m_subra_mani Shell Programming and Scripting 3 12-13-2005 04:13 PM



All times are GMT -4. The time now is 03:07 AM.