Sponsored Content
Top Forums Shell Programming and Scripting Convert Columns in Rows delimited by a strings Post 302889040 by Yoda on Tuesday 18th of February 2014 12:01:08 PM
Old 02-18-2014
Here is something I wrote based on your input data:
Code:
awk '
        BEGIN {
         print "UserName|DNSHostName|Caption|OSArchitecture|SerialNumber|NumberOfProcessors|TotalVisibleMemorySize|IPAddress|Name|Name|Description"
         n = split ( "UserName:DNSHostName:Caption:OSArchitecture:SerialNumber:NumberOfProcessors:TotalVisibleMemorySize:IPAddress", V, ":" )
         while ( ++k <= n )
               H[V[k]]
        }
        /UserName/ {
                f = 0
                c = 0
                split ( "", R )
        }
        function getval(par, str)
        {
                if ( par == "IPAddress" )
                        gsub ( /\{\"|\".*/, X, str )
                return str
        }
        /^Name/ {
                getline
                N[++c] = $0
                next
        }
        $1 in H {
                i = $1
                getline
                if ( !( $1 in H ) )
                {
                        if ( $1 != "Name" )
                                R[i] = getval( i, $0 )
                }
                else
                {
                        i = $1
                        getline
                        if ( $1 != "Name" )
                                R[i] = getval( i, $0 )
                }
                next
        }
        /Description/ {
                f = 1
                next
        }
        f && !/Description/ {
                for ( j = 1; j <= n; j++ )
                        printf "%s|", R[V[j]]
                printf "%s|%s|", N[1], N[2]
                printf "%s\n", $0
        }
' OFS='|' file

Feel free to make changes as per your requirement.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to convert columns to rows

Hi, I need a shell script for below requirement Input file P1 - 173310 P2 - 173476 P3 - 173230 P4 - 172737 P1 - 173546 P2 - 173765 P3 - 173876 P4 - 172989 Out put file P1 173310 173546 P2 173476 173765 P3 173230 173876 P4 172737 172989 Suresh (6 Replies)
Discussion started by: suresh3566
6 Replies

2. Shell Programming and Scripting

So I converted columns to rows but I want it to be tab delimited and also I want.....

Hi, So my file looks like this: title number JR 2 JR 2 JR 4 JR 5 NM 5 NM 8 NM 2 NM 8 I used this line that I wrote to convert it to rows so it will look like this: awk -F"\t" '!/^$/{a=a" "$3} END {for ( i in a) {print i,a}}' occ_output.tab > test.txt JR 2 2 4 5 NM 5 8... (4 Replies)
Discussion started by: kylle345
4 Replies

3. Shell Programming and Scripting

convert columns into rows

hi, Apologies if this has been covered. I have requirement where i have to convert a single column into multiple column. My data will be like this - 2 3 4 5 6 Output required - 2 3 4 5 6 (1 Reply)
Discussion started by: Nishithinfy
1 Replies

4. Shell Programming and Scripting

Convert Rows to Space Delimited Line

Hello, I would like to convert a list of rows to a space separated line. Any ideas? Input file: "Administration Tools" "Design Suite" "Dial-up Networking Support" "Editors" desired output "Administration Tools" "Design Suite" "Dial-up Networking Support" "Editors" Thanks,... (4 Replies)
Discussion started by: jaysunn
4 Replies

5. Shell Programming and Scripting

convert rows to columns

hi, i have the file as below: abc def ghi jkl i want the output as abc,def,ghi,jki please reply, Thanks (4 Replies)
Discussion started by: namitai
4 Replies

6. Shell Programming and Scripting

Convert few columns to rows

Hi! Does anybody help me in converting following data: INPUT looks like this: 20. 100. 30 200. 40. 400. 50. 100. 60. 200. 70. 400. 80. 200. 150. 210. 30. 100. OUTPUT should look like this: 20. 100. 30 200. 40. 400. 50. 100. 60. 200. 70.... (5 Replies)
Discussion started by: lovelinux
5 Replies

7. Shell Programming and Scripting

Convert Rows to Columns

Hi Everyone, Could someone shed some lights on how to convert the records in rows form into column basis. 172.29.59.12 IBM,8255-E8B 102691P 8 65536 MB 6100-04-11-1140 172.29.59.15 IBM,8255-E8B 102698P 4 45056 MB 6100-04-11-1140 IP SYS MODEL ... (6 Replies)
Discussion started by: ckwan
6 Replies

8. Shell Programming and Scripting

Convert rows to columns

I am looking to print the data in columns and after every 3 words it should be a new row. cat example.out | awk 'END { for (i = 0; ++i < m;) print _;print _ }{ _ = _ x ? _ OFS $1 : $1}' m=1| grep -i INNER I am looking to print in a new line after every 3 words. ... (2 Replies)
Discussion started by: lazydev
2 Replies

9. Shell Programming and Scripting

Convert rows to columns

hi folks, I have a sample data like what is shown below: 1,ID=1000 1,Org=CedarparkHospital 1,cn=john 1,sn=doe 1,uid=User001 2,uid=User002 2,ID=2000 2,cn=steve 2,sn=jobs 2,Org=Providence I would like to convert it into the below format: 1,1000,CedarparkHospital,john,doe,User001... (11 Replies)
Discussion started by: vskr72
11 Replies

10. Shell Programming and Scripting

Transpose comma delimited data in rows to columns

Hello, I have a bilingual database with the following structure a,b,c=d,e,f The right half is in a Left to right script and the second is in a Right to left script as the examples below show What I need is to separate out the database such that the first word on the left hand matches the first... (4 Replies)
Discussion started by: gimley
4 Replies
Session::Store::Postgres(3)				User Contributed Perl Documentation			       Session::Store::Postgres(3)

NAME
Apache::Session::Store::Postgres - Store persistent data in a Postgres database SYNOPSIS
use Apache::Session::Store::Postgres; my $store = new Apache::Session::Store::Postgres; $store->insert($ref); $store->update($ref); $store->materialize($ref); $store->remove($ref); DESCRIPTION
Apache::Session::Store::Postgres fulfills the storage interface of Apache::Session. Session data is stored in a Postgres database. SCHEMA
To use this module, you will need at least these columns in a table called 'sessions', or another name if you supply the TableName parameter. id char(32) # or however long your session IDs are. a_session text # This has an ~8 KB limit :( To create this schema, you can execute this command using the psql program: CREATE TABLE sessions ( id char(32) not null primary key, a_session text ); If you use some other command, ensure that there is a unique index on the table's id column. CONFIGURATION
The module must know what datasource, username, and password to use when connecting to the database. These values can be set using the options hash (see Apache::Session documentation). The options are: DataSource UserName Password Handle TableName Example: tie %hash, 'Apache::Session::Postgres', $id, { DataSource => 'dbi:Pg:dbname=database', UserName => 'database_user', Password => 'K00l' }; Instead, you may pass in an already-opened DBI handle to your database. tie %hash, 'Apache::Session::Postgres', $id, { Handle => $dbh }; AUTHOR
This modules was written by Jeffrey William Baker <jwbaker@acm.org> A fix for the commit policy was contributed by Michael Schout <mschout@gkg.net> SEE ALSO
Apache::Session, Apache::Session::Store::DBI perl v5.12.1 2007-09-28 Session::Store::Postgres(3)
All times are GMT -4. The time now is 12:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy