File formatting with awk

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers File formatting with awk
# 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:
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'

# 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 or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with awk'ing formatting this

Hi, I have a file below that I am wanting to awk. The lines of relevance are lines 7 and 9 $ nl /tmp/x 1 ADRCI: Release 11.2.0.3.0 - Production on Sun Jun 23 17:01:02 2013 2 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. 3 ADR base =... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

AWK/Shell script for formatting data in a file

Hi All, Need an urgent help to convert a unix file in to a particular format: **source file:** 1111111 2d2f2h2 3dfgsd3 ........... 1111111 <-- repeats in every nth line. remaining all lines will be different 123ss41 432ff45 ........... 1111111 <-- repetition qwe1234 123weq3... (1 Reply)
Discussion started by: rajivnairfis
1 Replies

3. UNIX for Dummies Questions & Answers

awk formatting

Hi all, I'm writing a simple awk code: awk 'BEGIN {FS="|"};{print "Type\tNumber\ttypes\tTotal";};{print $1, "\t", $2, "\t", $3, "\t", $4, "\t";}' db_query.txt it gives me the result: Type Number types Total XXX 498.0 5100.0 5274.661 Type Number types Total... (7 Replies)
Discussion started by: messi777
7 Replies

4. Shell Programming and Scripting

formatting awk

when i try this awk its giving out put as below. awk '!(/^$/||/--/||/selected/||/^ *$/){print $1}' tmp.txt output ===== 1 2010-08-03-12.31.26.126000 how excluede the 1st line ? i mean i want output only 2nd line i.e 2010-08-03-12.31.26.126000; (5 Replies)
Discussion started by: rocking77
5 Replies

5. Shell Programming and Scripting

AWK formatting help.

Dear all I require help with AWK regarding this situation Input is : fn1 12345 fn1 23456 fn3 231513 fn1 22325 fn3 123125 Desired output is fn1 12345 23456 22325 fn3 231513 123125 (5 Replies)
Discussion started by: Peasant
5 Replies

6. Shell Programming and Scripting

String formatting using AWK

Hi, I need to insert a line at a particular line number. I am using the below code: sed $REV_LINO_NO" i\\ # $CURRENT_DATE $NAME Changed pwd for cindy\'s id" file > file1 This code works, but the formatting is not as I expected. For example, I get lines as shown below... (2 Replies)
Discussion started by: sugan
2 Replies

7. Shell Programming and Scripting

formatting data file with awk or sed

Hi, I have a (quite large) data file which looks like: _____________ header part.. more header part.. x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 ... ... x59 x60 y1 y2 y3 y4... ... y100 ______________ where x1, x2,...,x60 and y1, y2,...y100 are numbers of 10 digits (so each line... (5 Replies)
Discussion started by: lego
5 Replies

8. UNIX for Advanced & Expert Users

Formatting file with Awk?

I have a file in CSV format (2 columns ID and Number of Items): AB1 ,,10 AB2 ,,20 AB2 ,, 30 AB3 ,, 10 AB4 ,, 20 AB4 ,, 30 AB4 ,, 40 AB5 ,, 50 AB6 ,, 10 AB7 ,, 20 AB7 ,, 30 AB7 ,, 40 ...... This file is produced daily i would like to get it in the following format, so... (6 Replies)
Discussion started by: SAMZ
6 Replies

9. Shell Programming and Scripting

Awk formatting of a data file - nested for loops?

Hello - is there any way in awk I can do... 4861 x(1) y(1) z(1) 4959 x(1) y(1) z(1) 5007 x(1) y(1) z(1) 4861 x(2) y(2) z(2) 4959 x(2) y(2) z(2) 5007 x(2) y(2) z(2) 4861 x(3) y(3) z(3) 4959 x(3) y(3) z(3) 5007 x(3) y(3) z(3) to become... 4861 x(1) y(1) z(1) 4861 x(2) y(2) z(2)... (3 Replies)
Discussion started by: catwoman
3 Replies

10. Shell Programming and Scripting

Formatting using awk

Let's say I write a simple script that contains the following: date | awk '{print $1}' date | awk '{print $2}' Of course, when I run the script the output will look similar to: Tue Mar What if I want my ouput to be on one line as follows: Tue Mar What changes would I need to... (2 Replies)
Discussion started by: cdunavent
2 Replies
Login or Register to Ask a Question