The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To cut entire column from a file and apend it to another file as another column sakthifire Shell Programming and Scripting 4 06-25-2008 01:27 AM
Inserting a column in a file dhanamurthy Shell Programming and Scripting 7 05-11-2008 07:29 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 05:57 AM
inserting into a data file paul1s UNIX for Dummies Questions & Answers 4 10-12-2006 11:47 PM
Inserting argument into top of a file Dev06 UNIX for Dummies Questions & Answers 7 10-05-2006 01:16 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2006
Registered User
 

Join Date: Jul 2005
Posts: 29
Inserting a new column in a file

Hey..

I'm writing a code to download some stuff from Informix database and put it on Xls. It works fine, but I have a problem fitting in a new requirement.

I have currently a file which has information like below.

f_name|Ronnie|Johnson|23.00|
f_sal|Ronnie|Jhonson|4000.00|
f_dept|Finance|Jr.Asst|23|

Now I need to insert a new column with a description corresponding to field name and that value needs to be inserted before it.

EmpName|f_name|Ronnie|Johnson|23.00|
EmpSalary|f_sal|Ronnie|Jhonson|4000.00|
EmpDept|f_dept|Finance|Jr.Asst|23|

I'm not sure of how to insert a value before a text moving the whole line to the right..

any thoughts please...
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-31-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,861
Try reeading the main page for join
IF you create a second file
Code:
EmpName|f_name
EmpSalary|f_sal
EmpDept|f_dept
you can join it to the first file. join creates a relation - in the database sense - almost like a join between two tables. Except it works per row - so if you have 30 lines in file1, then file2 needs 30 lines as well. If you want every line in the join to have a leading column
Reply With Quote
  #3 (permalink)  
Old 07-31-2006
Registered User
 

Join Date: Jul 2005
Posts: 29
Tried.. doesn't work

Hey..

I tried the way u told me .. I'm on AIX actually..

In the first file there are multiple entries of the field name.. like

f_name|Ronnie|Johnson|23.00|
f_name|xxxx|yyyy|000|
f_name|ssss|dddd|123|
f_sal|Ronnie|Jhonson|4000.00|
f_sal|xxxx|yyyy|000|
f_sal|ssss|dddd|123|
f_dept|Finance|Jr.Asst|23|

I created a second file like

f_name|EmpName
f_sal|EmpSalary
f_dept|EmpDept

and did a simple join after sorting both the files..
join file1 file2 > file3.

nothing happened. No error popped up an nothing is happening.. is AIX a problem..
i tried using "join -i" option but that is not available in AIX i guess.
the number of rows in the two files are obviously not the same

is there anyother way out ??
Reply With Quote
  #4 (permalink)  
Old 07-31-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Did you read the man page for join on AIX?
  1. You have delimiters that normally interfere with commands like these so you have to use the -t parameter (e.g. -t\|)
  2. You have to tell join what to join on (e.g. -1 1 -2 1)
  3. Optionally, you may want to specify output (e.g. -o 1.2,2.3,2.4)
so, with this:
Code:
join -t\| -1 1 -2 1 -o 1.2,2.3,2.4 file2 file1
you get this:
Code:
EmpName|Johnson|23.00
EmpName|yyyy|000
EmpName|dddd|123
EmpSalary|Jhonson|4000.00
EmpSalary|yyyy|000
EmpSalary|dddd|123
...on AIX even
Reply With Quote
  #5 (permalink)  
Old 08-01-2006
Registered User
 

Join Date: Jul 2005
Posts: 29
works ~

Works bud !!.. thanks much !
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0