|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| 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. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 |
|
|
|
|||
|
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 |
|
|||
|
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 ?? |
|
|||
|
Did you read the man page for join on AIX?
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
|
|
|||
|
works ~
Works bud !!.. thanks much !
|
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |