Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

File formatting with awk

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-29-2017   -   Original Discussion by omuhans123
omuhans123's Unix or Linux Image
omuhans123 omuhans123 is offline
Registered User
 
Join Date: Nov 2015
Last Activity: 27 January 2018, 9:09 AM EST
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
File formatting with awk

Hi, I would like to format the file input example to the specific output example. I have tried numerous different ways, however not able to extract the information as desired. Any assistance to get the file formatted would be truly appreciated:
Input:


Code:
server:<server url="http://speedtestwlfdle.rogers.com/speedtest/upload.php" lat="43.6000" lon="-79.6500" name="Mississauga, ON" country="Canada" cc="CA" sponsor="Rogers" id="8783"  url2="http://speedtestwlfdle.rogers.com/speedtest2/upload.php" host="speedtestwlfdle.rogers.com:8080" />
server:<server url="http://sp1.mornington.ca/speedtest/upload.php" lat="43.5658" lon="-80.9222" name="Milverton, ON" country="Canada" cc="CA" sponsor="Mornington Communications Ltd" id="10727"  url2="http://sp2.mornington.ca/speedtest/upload.php" host="sp1.mornington.ca:8080" />
server:<server url="http://speedy-1.tcc.on.ca/speedtest/upload.php" lat="43.5625" lon="-81.6980" name="Bayfield, ON" country="Canada" cc="CA" sponsor="Tuckersmith Communications" id="3533"  url2="http://speedy-2.tcc.on.ca/speedtest/upload.php" host="speedy-1.tcc.on.ca:8080" />

Output:


Code:
http://speedtestwlfdle.rogers.com/speedtest/upload.php;43.6000;-79.6500;Mississauga, ON;Canada;CA;Rogers,8783;http://speedtestwlfdle.rogers.com/speedtest2/upload.php;speedtestwlfdle.rogers.com:8080
http://sp1.mornington.ca/speedtest/upload.php;43.5658;-80.9222;Milverton, ON;Canada;CA,Mornington Communications Ltd;10727;http://sp2.mornington.ca/speedtest/upload.php;sp1.mornington.ca:8080
http://speedy-1.tcc.on.ca/speedtest/upload.php;43.5625;-81.6980;Bayfield, ON;Canada;CA;Tuckersmith Communications;3533;http://speedy-2.tcc.on.ca/speedtest/upload.php;speedy-1.tcc.on.ca:8080

Attempts to format:


Code:
awk 'BEGIN{FS="=";OFS=","}{print}' | sed 's/[{}"]//g'

Sponsored Links
    #2  
Old Unix and Linux 12-29-2017   -   Original Discussion by omuhans123
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 27 May 2018, 11:40 AM EDT
Location: San Jose, CA, USA
Posts: 11,311
Thanks: 638
Thanked 3,936 Times in 3,367 Posts
As has been suggested before, when posting in this forum please tell us what operating system and shell you're using.

And, instead of just showing us a three line sample input file and a three line sample output file, please also describe the logic that governs the changes you are trying to make.

The code you're using is going to a lot of effort to remove braces from the output, but since there aren't any braces in your sample input; it isn't clear why you are doing that.

The code you're using sets the output field separator to a comma, but your sample output seems to use semicolon as a field separator.

Please clearly explain what you are trying to do and be sure that the sample output you have provided really matches the output you hope to produce from that input.
Sponsored Links
    #3  
Old Unix and Linux 12-30-2017   -   Original Discussion by omuhans123
omuhans123's Unix or Linux Image
omuhans123 omuhans123 is offline
Registered User
 
Join Date: Nov 2015
Last Activity: 27 January 2018, 9:09 AM EST
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
Apologies for not being clear. The idea is to have the file formatted in a semicolon way, without the description in front. If you look at the raw file it describes everything with e.g. url= which I would like to remove and the quotation marks around the info. So the idea is to have a well formatted file output with only the information, also most like a CSV using the e.g. url as header instead of in the body itself.
    #4  
Old Unix and Linux 12-30-2017   -   Original Discussion by omuhans123
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 26 May 2018, 5:24 PM EDT
Location: Aachen, Germany
Posts: 12,756
Thanks: 417
Thanked 3,923 Times in 3,607 Posts
And Don Cragun's other questions?
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AWK/Shell script for formatting data in a file rajivnairfis Shell Programming and Scripting 1 05-14-2012 07:57 AM
awk formatting messi777 UNIX for Dummies Questions & Answers 7 04-03-2012 05:28 AM
formatting data file with awk or sed lego Shell Programming and Scripting 5 03-26-2010 10:11 PM
Formatting file with Awk? SAMZ UNIX for Advanced & Expert Users 6 08-13-2008 11:27 AM
Awk formatting of a data file - nested for loops? catwoman Shell Programming and Scripting 3 07-04-2008 02:27 AM



All times are GMT -4. The time now is 11:41 AM.