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
ksh scripting help praveenbvarrier Shell Programming and Scripting 1 04-15-2008 10:19 AM
sql scripting help sam786 Shell Programming and Scripting 3 12-10-2007 12:31 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 AM
scripting guru's pls help me with scripting on AIX thatiprashant Shell Programming and Scripting 1 01-20-2006 07:58 PM
Scripting? woofie What's on Your Mind? 1 03-09-2005 07:03 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
  #8 (permalink)  
Old 05-14-2008
Northerner Northerner is offline
Registered User
  
 

Join Date: May 2008
Location: Sheffield
Posts: 11
The output from this awk command is
0508 0601 LVTS4687 58 1ltreb_shu1l110 shu1l110
0509 0108 LVTS4687 58 1ltreb_shu1l110 shu1l110
0509 0108 LVTS4687 58 1ltreb_shu1l110 shu1l110
0509 0108 LVTS4687 58 1ltreb_shu1l110 shu1l110
0508 2206 LVTS5035 98 1sy_unix_live_dmz_duplex_15_35 srublae03-mgt
0508 2206 LVTS5035 98 1sy_unix_live_dmz_duplex_15_35 srublae03-mgt
0508 2206 LVTS5035 98 1sy_unix_live_dmz_duplex_15_35 srublae03-mgt
0508 2206 LVTS5430 98 1
0508 2206 LVTS5430 98 1
0508 2206 LVTS5430 98 1
0508 2206 LVTS5431 98 1lmurb_shu1l282 shu1l282-sy
0508 2206 LVTS5431 98 1lmurb_shu1l282 shu1l282-sy
0508 2206 LVTS5431 98 1lmurb_shu1l282 shu1l282-sy
0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT

Which is almost there apart from there being no space between parm5 and 6 and also parm 4 is reduced to the last 2 digits. Apologies for my ignorance on this but I have never used "awk" before. The file should look like this

0508 0601 LVTS4687 58 1 ltreb_shu1l110 shu1l110
0509 0108 LVTS4687 58 1 ltreb_shu1l110 shu1l110
0509 0108 LVTS4687 58 1 ltreb_shu1l110 shu1l110
0509 0108 LVTS4687 58 1 ltreb_shu1l110 shu1l110
0508 2206 LVTS5035 98 1 sy_unix_live_dmz_duplex_15_35 srublae03-mgt
0508 2206 LVTS5035 98 1 sy_unix_live_dmz_duplex_15_35 srublae03-mgt
0508 2206 LVTS5035 98 1 sy_unix_live_dmz_duplex_15_35 srublae03-mgt
0508 2206 LVTS5430 98 1
0508 2206 LVTS5430 98 1
0508 2206 LVTS5430 98 1
0508 2206 LVTS5431 98 1 lmurb_shu1l282 shu1l282-sy
0508 2206 LVTS5431 98 1 lmurb_shu1l282 shu1l282-sy
0508 2206 LVTS5431 98 1 lmurb_shu1l282 shu1l282-sy
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT

Is it possible to format the file so each parm starts in a specific column for example

Parm1 in Col1
Parm2 in Col6
Parm3 in Col12
Parm4 in Col22
Parm5 in Col27
Parm6 in Col30
Parm7 in Col65
  #9 (permalink)  
Old 05-14-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,793
The first problem (the missing space) is trivial:

Code:
awk 'NR==FNR{_[$1]=$3 FS $6;next}$NF=$NF FS _[$3]' file1 file2
Quote:
[...]and also parm 4 is reduced to the last 2 digits
Could you be more specific?

Quote:
Is it possible to format the file so each parm starts in a specific column for example

Parm1 in Col1
Parm2 in Col6
Parm3 in Col12
Parm4 in Col22
Parm5 in Col27
Parm6 in Col30
Parm7 in Col65
Provide an example, please.
  #10 (permalink)  
Old 05-14-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
That sounds like a simple printf specifier.

Code:
awk whatever ... |
awk '{ printf ("%5s%6s%9s%5s%3s%35s%s\n", $1, $2, $3, $4, $5, $6, $7) }'
(Sorry, might have miscalculated the width of a few fields. Modifying the earlier script to do this is itself is probably not too hard either.)

I don't see anything which would be reducing $6 to just two characters.
  #11 (permalink)  
Old 05-14-2008
Northerner Northerner is offline
Registered User
  
 

Join Date: May 2008
Location: Sheffield
Posts: 11
The original file2 had the following

0508 2206 LVTS5431 98 1
0506 0920 LVTS5750 141 3

but the output to file3 shows
0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT

where the 141 is truncated to 41

the final output I would like to see so that each parm is alligened in the specific columns
Starting in column
1 6 12 22 27 30 65
0508 0601 LVTS4687 58 1 ltreb_shu1l110 shu1l110

Last edited by Northerner; 05-14-2008 at 08:51 AM..
  #12 (permalink)  
Old 05-14-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Whatever is causing that is not happening here, and it's unlear why it would be caused by Radoulov's script; it doesn't alter $6. Might your input file have been corrupted at some point?
  #13 (permalink)  
Old 05-14-2008
Northerner Northerner is offline
Registered User
  
 

Join Date: May 2008
Location: Sheffield
Posts: 11
Checked the file and you are correct the input file is wrong, so I think with the help of Radoulov and Era I've got there, many thanks indeed.

Last edited by Northerner; 05-14-2008 at 09:40 AM..
  #14 (permalink)  
Old 05-14-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
It's not showing as aligned any particular way here. Maybe if you post an example with code tags we can see better what you mean. (This regular HTML edit box will squeeze all spaces down to one.)
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 06:31 AM.


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