Want to split awk command | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Want to split awk command

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 06-29-2013
mjf mjf is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 19 September 2014, 11:36 AM EDT
Location: Newtown, PA
Posts: 123
Thanks: 7
Thanked 29 Times in 28 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 06-29-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 19 September 2014, 1:56 PM EDT
Location: Galactic Empire
Posts: 3,383
Thanks: 234
Thanked 1,208 Times in 1,134 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 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 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 07-01-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 19 September 2014, 1:56 PM EDT
Location: Galactic Empire
Posts: 3,383
Thanks: 234
Thanked 1,208 Times in 1,134 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 07-01-2013
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 September 2014, 5:57 AM EDT
Location: San Jose, CA, USA
Posts: 4,677
Thanks: 180
Thanked 1,564 Times in 1,331 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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 08:11 AM.