Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google site



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread 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...
Sponsored Links
  #2 (permalink)  
Old 07-31-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,117
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
  #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 ??
  #4 (permalink)  
Old 07-31-2006
Registered User
 

Join Date: Jan 2005
Posts: 683
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
  #5 (permalink)  
Old 08-01-2006
Registered User
 

Join Date: Jul 2005
Posts: 29
works ~

Works bud !!.. thanks much !
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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 05:27 AM
Inserting a column in a file dhanamurthy Shell Programming and Scripting 7 05-11-2008 11: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 09:57 AM
inserting into a data file paul1s UNIX for Dummies Questions & Answers 4 10-13-2006 03:47 AM
Inserting argument into top of a file Dev06 UNIX for Dummies Questions & Answers 7 10-05-2006 05:16 PM



All times are GMT -4. The time now is 05:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0