The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Extracting part of a string sam_78_nyc Shell Programming and Scripting 8 04-25-2007 07:37 PM
Extracting part of the basename madhunk Shell Programming and Scripting 3 02-13-2007 11:54 AM
extracting from tar.bz2 Raom UNIX for Advanced & Expert Users 1 03-07-2006 10:33 AM
extracting uncommon part between two files sabyasm Shell Programming and Scripting 2 11-06-2005 01:25 PM
extracting from a string preetikate Shell Programming and Scripting 1 03-11-2004 08:08 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-20-2008
finalight finalight is offline
Registered User
  
 

Join Date: May 2008
Posts: 51
need help extracting this part

Code:
           JADE TRADER       143W       MYPEN  40   HC   M    X10    28    7	1      0
                                        MYPEN  20   GP   X    X10    15    2	1      0
                                        MYPEN  40   GP   X    X10    28    7	1      0
                                        MYPEN  20   GP   L    X10    15    2	1      0
       BUNGA TERATAI 3       5055       NZLYT  20   GP   X    X11    17    8	1      0
          MOL SPLENDOR      0307A       MUPLU  40   HC   X    X11    10    2	2      0
                                        MUPLU  40   HC   U    X11    10    2	1      0
i doing a script to extract the result and want the result to be like this

JADE TRADER 143W MYPEN 40 HC M X10 28 7 1 0
JADE TRADER 143W MYPEN 20 GP X X10 15 2 1 0
JADE TRADER 143W MYPEN 40 GP X X10 28 7 1 0
JADE TRADER 143W MYPEN 20 GP L X10 15 2 1 0
BUNGA TERATAI 3 5055 NZLYT 20 GP X X11 17 8 1 0
MOL SPLENDOR 0307A MUPLU 40 HC X X11 10 2 2 0
MOL SPLENDOR 0307A MUPLU 40 HC U X11 10 2 1 0

so how can I achieve this result, given that I do not know how many subsets are there for each of the first field..?
  #2 (permalink)  
Old 05-20-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
Code:
awk ' NF > 9 { m=$1 " " $2 " " $3;
        printf("%s %s %s %s %s %s %s %s %s %s \n" ,m, $4, $5, $6, $7, $8, $9, $10, $11, $12)  ; next }
        { printf("%s %s %s %s %s %s %s %s %s %s \n" ,m, $1, $2, $3, $4, $5, $6, $7, $8, $9) }'
  #3 (permalink)  
Old 05-20-2008
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,402
Try...
Code:
awk '{a=substr($0,1,40);print (a~"[^ ]"?p=a:p) substr($0,41)}' file1 >  file2
  #4 (permalink)  
Old 05-20-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
Try this,

awk ' NF > 10 { val1=$1;val2=$2;val3=$3; print $0 ; next}
{print val1,val2,val3,$0}' filename


Thanks
Penchal
  #5 (permalink)  
Old 05-20-2008
finalight finalight is offline
Registered User
  
 

Join Date: May 2008
Posts: 51
awk: syntax error near line 2
awk: bailing out near line 2
  #6 (permalink)  
Old 05-20-2008
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,402
Quote:
Originally Posted by finalight View Post
awk: syntax error near line 2
awk: bailing out near line 2
Which post are you referring to?

This is what I get a the ksh prompt (represented by "$")....
Code:
$ cat file1
           JADE TRADER       143W       MYPEN  40   HC   M    X10    28    7    1      0
                                        MYPEN  20   GP   X    X10    15    2    1      0
                                        MYPEN  40   GP   X    X10    28    7    1      0
                                        MYPEN  20   GP   L    X10    15    2    1      0
       BUNGA TERATAI 3       5055       NZLYT  20   GP   X    X11    17    8    1      0
          MOL SPLENDOR      0307A       MUPLU  40   HC   X    X11    10    2    2      0
                                        MUPLU  40   HC   U    X11    10    2    1      0

$ awk '{a=substr($0,1,40);print (a~"[^ ]"?p=a:p) substr($0,41)}' file1 > file2
$ cat file2
           JADE TRADER       143W       MYPEN  40   HC   M    X10    28    7    1      0
           JADE TRADER       143W       MYPEN  20   GP   X    X10    15    2    1      0
           JADE TRADER       143W       MYPEN  40   GP   X    X10    28    7    1      0
           JADE TRADER       143W       MYPEN  20   GP   L    X10    15    2    1      0
       BUNGA TERATAI 3       5055       NZLYT  20   GP   X    X11    17    8    1      0
          MOL SPLENDOR      0307A       MUPLU  40   HC   X    X11    10    2    2      0
          MOL SPLENDOR      0307A       MUPLU  40   HC   U    X11    10    2    1      0

$
If on Solaris, use nawk.
  #7 (permalink)  
Old 05-20-2008
finalight finalight is offline
Registered User
  
 

Join Date: May 2008
Posts: 51
oh nvm, because the data i post is just a part of the whole file actually..i was trying to find some other way to do it
Sponsored Links
Closed Thread

Bookmarks

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0