Home Man
Today's Posts

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

Login to Reply

Thread Tools Search this Thread
# 1  
Old 12-29-2017
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:
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" />

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:
awk 'BEGIN{FS="=";OFS=","}{print}' | sed 's/[{}"]//g'

# 2  
Old 12-29-2017
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.
# 3  
Old 12-30-2017
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 12-30-2017
And Don Cragun's other questions?
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh file formatting user052009 Shell Programming and Scripting 3 02-03-2017 01:01 PM
Formatting file data to another file (control character related) hk6279 Shell Programming and Scripting 3 09-24-2012 03:17 AM
Need help in formatting a file. jpkumar10 Shell Programming and Scripting 2 07-16-2012 05:57 AM
File Formatting prasson_ibm Shell Programming and Scripting 4 07-15-2012 06:55 AM
Formatting csv file kingbp Shell Programming and Scripting 0 03-28-2011 04:29 PM
File Formatting saurabhbaisakhi Shell Programming and Scripting 1 05-13-2010 11:31 AM
help with file formatting prvnrk Shell Programming and Scripting 18 09-18-2009 01:41 PM
Formatting a file. abhilasha UNIX for Dummies Questions & Answers 1 01-14-2008 06:51 AM
Formatting the Log file sharif Shell Programming and Scripting 5 02-24-2007 09:31 AM
file formatting ? cstovall Shell Programming and Scripting 16 07-20-2005 08:05 AM

All times are GMT -4. The time now is 02:05 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
Show Password