The UNIX and Linux Forums  


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
To convert multi format file to a readable ascii format gaur.deepti UNIX for Dummies Questions & Answers 5 03-25-2008 03:03 PM
Convert UTF8 Format file to ANSI format rajreddy UNIX for Dummies Questions & Answers 9 05-25-2007 09:26 AM
Convert UTF8 Format file to ANSI format rajreddy UNIX for Advanced & Expert Users 1 05-24-2007 07:40 AM
format file happyv Shell Programming and Scripting 14 03-15-2007 04:30 PM
man format file trynew Shell Programming and Scripting 3 10-07-2004 04:17 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-13-2008
ratheesh ratheesh is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
Question Need help to format a file

Hi All,
I am new to the unix scripting part . can some one help to to format file with required fields.

current file looks like ..


aaa Fibre aaa aaa 01C1:01C9
1CB
01CD
01CF
1249
bbb Fibre bbb bbb 01D1
0722
072A
124A
ccc Fibre ccc ccc 01D9
124B
ddd Fibre ddd ddd 01E1
eee Fibre eee eee 01CA
0201
0209
0211
0219
0221
0229
0231
fff Fibre fff fff 0178:0185
0189
0191
107E
1246

The output file required is



aaa Fibre aaa aaa 01C1:01C9
aaa Fibre aaa aaa 01CB
aaa Fibre aaa aaa 01CD
aaa Fibre aaa aaa 01CF
aaa Fibre aaa aaa 1249
bbb Fibre bbb bbb 01D1
bbb Fibre bbb bbb 0722
bbb Fibre bbb bbb 072A
bbb Fibre bbb bbb 124A
ccc Fibre ccc ccc 01D9
ccc Fibre ccc ccc 124B
ddd Fibre ddd ddd 01E1
eee Fibre eee eee 01CA
eee Fibre eee eee 0201
eee Fibre eee eee 0209
eee Fibre eee eee 0211
eee Fibre eee eee 0219
eee Fibre eee eee 0221
eee Fibre eee eee 0229
eee Fibre eee eee 0231
fff Fibre fff fff 0178:0185
fff Fibre fff fff 0189
fff Fibre fff fff 0191
fff Fibre fff fff 107E
fff Fibre fff fff 1246

Thanks in advance ..
  #2 (permalink)  
Old 02-13-2008
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,787

Code:
awk '{if(NF>4)
      { keep=sprintf("%s %s %s %s ", $1, $2, $3, $4)
       print $0
      }
      else
       print keep, $0
      } ' filename > newfilename

  #3 (permalink)  
Old 02-13-2008
ratheesh ratheesh is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
Smile Thanks !!

Hi Jim,

Thanks for your help ..
it is working fine ..
Closed Thread

Bookmarks

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 02:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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