If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > awk help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-04, 16:56
abe6162 abe6162 is offline
Registered User
 
Join Date: Feb 2004
Posts: 24
Red face awk help

I have a file that looks like this ...

93459;217800;American Company;LF
238929;2800;Test Company;LF

I need to format it to look like ..

2800;238929;LF;Test Company
217800;93459;LF;American Company

I ran the command

awk -F; '{print $2";"$1";"$4";"$3}'

This command however formats my data as such..

2800;238929;LF ;Test Company
217800;93459;LF ;American Company

I believe the reason this is happening is because there are some blank spaces after "LF". Is there anyway to get it to format the way I want it without going through the whole file and deleting all the blank spaces.
Reply With Quote
  #2 (permalink)  
Old 02-24-04, 17:29
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
You could substitute the trailing spaces of $4 with an empty string. Also, to use ";" as the Output Field Separator, you may aswell set OFS.
Code:
awk 'BEGIN(FS=";"; OFS=";"}{sub(/ *$/,"",$4); print $2,$1,$4,$3}' yourFile
Damian
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On