Add extra columns help

Thread Tools Search this Thread
# 1  
Add extra columns help

Hi Gurus,

This below script adds a column extra to my flat file..But how can i add another column, Say if i just put mention an other column beside the first does get generated but as one column only

while IFS="" read r; do
printf "dummy\t%s\n" "$r" 
done < xxx.txt > zzz.txt

I kept another column dummy2 next to dummy.. it gets generated, separated by a tab as well but when reimport into my code..I see it as a single column

Last edited by radoulov; 10-10-2011 at 11:53 AM.. Reason: Code tags!
# 3  
lets say i have a file separated by a tab delimiter


abc   bbc  cbz  ddd

Now , i want to add a column xxx....The above script works fine...But now
I need to add one other column yyy..the script works fine..but when i re-import i see that this is marked as a single column despite being separated by a tab..

i want

yyy  xxx  abc  bbc   cbz  ddd.........

xxx and yyy shud be tab separated.

Last edited by radoulov; 10-10-2011 at 11:54 AM.. Reason: Code tags!
# 4  
As you specify, the script works fine.

Then the problem is either in the way you are importing the data or in the way you are reading it.
# 5  
Shell Life i appreciate your prompt replies..But am into forums for answers not just anybody can simply write whatever comes to their minds...These are all real time requirements so please reply if only you know the answer...
# 6  
Read about and test the command "paste"
man paste

$ cat f3
$ cat f4
$ paste -d"\t" f3 f4
hjkfdq    7892789
fjklsq    120392
flfd    109327
fjdlsq    25483
jdslk    3471

$ paste -d"\t" f3 f4 f3 f3 f4 f3
hjkfdq    7892789    hjkfdq    hjkfdq    7892789    hjkfdq
fjklsq    120392    fjklsq    fjklsq    120392    fjklsq
flfd    109327    flfd    flfd    109327    flfd
fjdlsq    25483    fjdlsq    fjdlsq    25483    fjdlsq
jdslk    3471    jdslk    jdslk    3471    jdslk

Last edited by ctsgnb; 10-11-2011 at 05:18 AM..
# 7  
See the thing is , Actually i have some 100 rows

xxx 000 111 222 333 444
yyy 000 111 222 333 444
zzz 000 111 222 333 444
Now the requirement is add a dummy column say, Fiscal year FY11

The code which i have works fine..what it would do is

xxx 000 111 222 333 444 FY11
yyy 000 111 222 333 444 FY11
zzz 000 111 222 333 444 FY11

Now i want to add an other column..when i do it it is getting separated by a tab but when i import it into my is seen as a single column.....U can try using excel it would be more clear.

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
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 ...... Shell Programming and Scripting
Shell Programming and Scripting
Request: How to Parse dynamic SQL query to pad extra columns to match the fixed number of columns
Hello All, I have a requirement in which i will be given a sql query as input in a file with dynamic number of columns. For example some times i will get 5 columns, some times 8 columns etc up to 20 columns. So my requirement is to generate a output query which will have 20 columns all the...... Shell Programming and Scripting
Shell Programming and Scripting
Randomly inserting extra columns into csv file
Hi Tech Guru, I have a test file as below , which needs some more fields to be populated randomly : dks3243;12;20130823;1420;25m;0;syt dks3243;rocy;10 dks3243;kiop;18 sde21p4;77;20151210;8479;7py;9;vfr sde21p4;temp;67 sfq6i01;12;20120123;3412;4rd;7;jui sfq6i01;uymk;90 sfq6i01;kiop;51 ...... Shell Programming and Scripting
Shell Programming and Scripting
Remove extra characters and sum the columns
I have data extracted like this: A=%123% B=%456% C=%789% A=%111% B=%222% C=%333% A=%777% B=%888% C=%999% Can someone please help me with a script to remove all the % signs and get the totals for A, B and C. So output will be: A=1368 B=666 C=2664 Thank you!... Shell Programming and Scripting
Shell Programming and Scripting
how to flip values of two columns and add an extra column
Hi guys, Couldn't find the solution of this problem. Please Help! I have a file- Input_File TC200232 92 30 TC215306 2 74 TC210135 42 14 I want an output file in which if column2>column3, the values are swapped and an additional column with value Rev_Com is...... Shell Programming and Scripting
Shell Programming and Scripting