How to insert dummy columns


 
Thread Tools Search this Thread
Operating Systems AIX How to insert dummy columns
# 1  
Old 04-18-2008
How to insert dummy columns

Hi

My requirement is as follows,

I have a input feed coming for X as

A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P;
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P;
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P;
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P;
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P;


any other feed coming from Y is as

A,B,C,D,1,2,E,F,G,H,I,J,3,4,5,K,L,M,6,7,8,N,O,P

Now I want to merge both the feed and make the output as
A,B,C,D,0,0,E,F,G,H,I,J,0,0,0,K,L,M,0,0,0,N,O,P X
A,B,C,D,1,2,E,F,G,H,I,J,3,4,5,K,L,M,6,7,8,N,O,P Y

Any suggestions......

Regards,
SM
# 2  
Old 04-19-2008
As far as i can see the result consists only of the second feed with all the numerical values set to zero. Maybe i misunderstood your requirement.

To set all the fields consisting of numerical values to "0" use the following sed filter:

Code:
sed 's/[0-9][0-9]*,/0,/g'

I hope this helps.
# 3  
Old 04-19-2008
By merge do you mean read in both lines and then sort the output horizontally?
Here is an awkward try:
Code:
awk '{
           FILENAME=="file1" { arr[FNR]=$0 }
           FILENAME=="file2" { arr[FNR]= arr[FNR] " " $0}
        }
        END for (in in arr) { print arr[i]} ' file1  file2 | \
while read str
do
 echo $str | tr " " "\n" | sort | tr "\n" " "
 echo
done  > newfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to Insert three extra columns in csv file

Hello Experts, I got a requirement i have a input file which am getting from different source,Now i want to add extra 3 columns to this file like BASE,ACTUAL and DATE. Input File Looks like QUAL CHGE TYP LAW COM1 COM2 A 1 X SED HO ASE B 3 Z CDE SE ... (5 Replies)
Discussion started by: ahmed.vaghar
5 Replies

2. Shell Programming and Scripting

Insert Columns before the last Column based on the Count of Delimiters

Hi, I have a requirement where in I need to insert delimiters before the last column of the total delimiters is less than a specified number. Say if the delimiters is less than 139, I need to insert 2 columns ( with blanks) before the last field awk -F 'Ç' '{ if (NF-1 < 139)} END { "Insert 2... (5 Replies)
Discussion started by: arunkesi
5 Replies

3. UNIX for Dummies Questions & Answers

Match and insert columns

Hi, I've got two files to match. File one: a1 b c d e a2 b c d e a3 b c d e a4 b c d e and file 2 a1 1 2 3 4 a2 5 6 7 8 a3 9 10 11 12 a4 1 2 3 4 I need to match them by the first column and add the four columns of file 2 to the file 1 so that those added columns go as columns... (5 Replies)
Discussion started by: zajtat
5 Replies

4. Shell Programming and Scripting

Insert space in specific column among many columns

Hello, I have some problem in inserting the space for the pairs of columns. I have the input file : I used this code below in replacing it using space in specific column (replace space in each two columns) sed -e "s/,/ /2" -e "s/,/ /3" inputfile Output showed : However, I have many... (3 Replies)
Discussion started by: awil
3 Replies

5. Shell Programming and Scripting

Insert empty columns in a flat file

Hi, I have a tab delimited flat file, for example shown below Name Desg Loc a b c d e fI want to insert an empty column inbetween the column Desc and Loc, the result should be like shown below: Name LName Desg Loc a b c d e ... (6 Replies)
Discussion started by: sampoorna
6 Replies

6. Shell Programming and Scripting

insert dummy values in a file

Hey guys, i have a file a.txt and i need to insert a dummy data into it as per the below pattern.. bash: cat a.txt 1234,34 3434,45 4545,56 3434,56 Now i need the file in the below pattern 1234,34,a0001,C_01 3434,45,a0002,C_02 4545,56,a0003,C_03 3434,56,a0004,C_04 here the count of... (3 Replies)
Discussion started by: jaituteja
3 Replies

7. Shell Programming and Scripting

How do i find the first number in each line and insert dummy string into the missing columns?

Hi, I have one input file with the following content: MY_inpfile.txt Aname1 Cname1 Cname2 1808 5 Aname2 Cname1 1802 47 Bname1 ? 1819 22 Bname2 Cname1 1784 11 Bname3 1817 9 Zname1 Cname1 1805 59 Zname2 Cname1 Cname2 Cname3 1797 27 Every line in my input file have a 4 digit... (5 Replies)
Discussion started by: Szaffy
5 Replies

8. Shell Programming and Scripting

Selecting Specific Columns and Insert the delimiter TAB

Hi, I am writing a Perl Script for the below : I have a data file that consists of the header information which is 231 Lines and the footer information as 4 lines. The total number of line including the header and footer 1.2 Million with Pipe Delimited file. For example: Header Information:... (4 Replies)
Discussion started by: filter
4 Replies

9. UNIX for Dummies Questions & Answers

Insert text in datafile with uneven columns

Dear Unix Gurus, I have a dataset consisting of a number of uneven columns. What I would like to do is fill up the missing rows with an arbitrary text of fixed value so that all columns now have an equal number of rows. for example, in the sample datafile below... 1.0 1.3 0.25 2.2 2.0... (2 Replies)
Discussion started by: tintin72
2 Replies

10. Shell Programming and Scripting

need to insert two columns (or two feilds) at the begining of the table

Hey guys/gals, So here is what i'm starting with...its a Solaris patch diag output. bash-3.0# pca -l Using /var/tmp/patchdiag.xref from Oct/20/08 Host: seiftsx4140 (SunOS 5.10/Generic_127128-11/i386/i86pc) List: missing Patch IR CR RSB Age Synopsis ------ -- - -- --- ---... (3 Replies)
Discussion started by: zeekblack
3 Replies
Login or Register to Ask a Question