LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-16-2008, 06:24 PM   #1
cgcamal
Member
 
Registered: Nov 2008
Location: Tegucigalpa
Posts: 78

Rep: Reputation: 16
Transpose info between blocks from column to lines arragement


Please some help from the experts,

I hope anyone could help me with the way to make a script with awk to send the information of the column 1 and 2 in a new file in lines. I´m not handle Unix, but somebody told me awk it could be the answer.

I have a text file with system user information in two columns divided in blocks, (many blocks) beginning with "Account user". Within the first column there are words that are repeated through the file in other blocks information for other users. In second column is written the info related to every particular user defined in the system as we can see below of every "Account user" field in first column.

*Some blocks contain less fields or lines than others.

I'd like to tabulate, organize the same information putting the repeated fields in the first column as headers in a new file. Saying that the block that contain the maximun number of fields in the 1rst column has 100 fields, the number of columns (or headers) in the new file would be 100, without count the fixed column that would contain the header "Account user". In total would be 101.

Example:

I have this:

Account user
jsmith
Full Name ---------------------- John Smith
User's comment ------------------With this profile I can change everything
Password last set -----------------10/22/08 2:18 PM
Workstations allowed --------- ----All
Group Memberships --------------Administrators Users
Account user
mkendall
Full Name ---------------------- Mark Kendall
Password last set ----------------11/02/2008 7:19
Group Memberships --------- Operators Users
.
.
.
and continues..

I'd like to obtain an arrangement as follow:
(The blocks with less fields would appear with empty spaces under some columns)


Code:
Account user--Full Name-----User's comment------------Password last set----Workstations allowed--Group Memberships
jsmith--------John Smith----I can change everything------10/22/08 2:18 PM----------All----------Administrators Users
mkendall------Mark Kendall-------------------------------11/02/08 7:19 AM-------------------------Operators Users
Any suggestion or script example on how can I do this will be appreciated.

Thanks in advance.
 
Old 11-16-2008, 08:48 PM   #2
raj77_in
LQ Newbie
 
Registered: Oct 2008
Posts: 26

Rep: Reputation: 15
I think the simplest way to do this would be to parse the file in sequential manner with a perl of shell script and then put them in a single row. Example pseudo code:

get line
if line == /Accounf user/ then
{
print newline
get line; print line
get line
if line =~ /Full Name/ then print name else print tab
and so on
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed command to print matching lines and 2 lines above.. DX398 Programming 12 10-01-2008 08:25 AM
[sed || gawk]: find and delete blocks and lines from file Hisu Programming 1 09-16-2008 02:01 PM
Asterisk box to connect VoIP lines with normal telephone lines. sraju Linux - Software 1 11-08-2006 12:38 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM
printer printing vertical lines at beginning and end of lines makhand Linux - Hardware 0 09-02-2005 02:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration