👤
Home Man
Search
Today's Posts
Register

This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Printing records in different format

Tags
awk, awk in awk, record formating, shell script

 

 
Thread Tools Search this Thread
# 1  
Old 08-17-2012
Printing records in different format

Hi all,
I have a input file say record.txt

hostname IP_address Port_No Version
A 10.10.10.1 80 6.02
B 10.10.10.2 81 6.03
C 10.10.10.3 82 6.04

row 1 has 4 field headings : hostname, IP_address, Port_No and Version.
and from 2nd row onwards the actual records start.

now i need to convert these records in a single line containing hostname and 1 property at a time,

say, something like this...

hostname=A/attribute=IP_address/value=10.10.10.1
hostname=A/attribute=Port_No/value=80
hostname=A/attribute=Version/value=6.02
hostname=B/attribute=IP_address/value=10.10.10.2
hostname=B/attribute=Port_No/value=81
hostname=B/attribute=Version/value=6.03
hostname=C/attribute=IP_address/value=10.10.10.3
hostname=C/attribute=Port_No/value=82
hostname=C/attribute=Version/value=6.04

I tried doing this using AWK but no luck...
Please help..

Thanx in advance...
# 2  
Old 08-17-2012
Code:
awk '
NR==1{for(i=1;i<=NF;i++) h[i]=$i; next}
{
 for(i=2;i<=NF;i++)
  print h[1] "=" $1 "/attribute=" h[i] "/value=" $i
}' record.txt

The Following User Says Thank You to elixir_sinari For This Useful Post:
PranavEcstasy (08-17-2012)
# 3  
Old 08-17-2012
Thanks

Thank you elixir, it worked...
 

« 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
Help in printing records where there is a 'header' in the first record ??? newbie_01 UNIX for Beginners Questions & Answers 2 12-28-2017 02:36 AM
Help required in printing in specific format shash Shell Programming and Scripting 4 12-16-2015 01:02 PM
Printing files in a specific format AAHinka UNIX for Dummies Questions & Answers 2 05-01-2015 04:54 PM
Help with printing advance output format from a file AAHinka UNIX for Dummies Questions & Answers 1 04-20-2015 12:09 PM
Help with printing output format from a file AAHinka UNIX for Dummies Questions & Answers 2 04-16-2015 08:38 AM
How can I get certain records from this file format? mrn6430 UNIX for Dummies Questions & Answers 11 06-04-2013 02:10 PM
Printing records which meet condition using awk pinnacle Shell Programming and Scripting 2 05-19-2009 02:18 PM
Format & re-arrange the records rlmadhav Shell Programming and Scripting 6 01-09-2009 04:25 PM
Printing Formatted Records From A File Silentwolf Shell Programming and Scripting 3 09-03-2008 02:31 AM
printing out procedures in unknown format rjtrjt UNIX for Dummies Questions & Answers 1 06-19-2003 03:36 PM


All times are GMT -4. The time now is 02:48 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password