Add extra columns help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Add extra columns help
# 1  
Old 10-07-2011
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 column..it does get generated but as one column only

Code:
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 12:53 PM.. Reason: Code tags!
# 2  
Old 10-07-2011
Please post your input and desired output.
# 3  
Old 10-10-2011
lets say i have a file separated by a tab delimiter

Ex:

Code:
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

Code:
yyy  xxx  abc  bbc   cbz  ddd.........

xxx and yyy shud be tab separated.

Last edited by radoulov; 10-10-2011 at 12:54 PM.. Reason: Code tags!
# 4  
Old 10-10-2011
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  
Old 10-11-2011
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  
Old 10-11-2011
Read about and test the command "paste"
Code:
man paste

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

Code:
$ 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 06:18 AM..
# 7  
Old 10-11-2011
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 code..it is seen as a single column.....U can try using excel it would be more clear.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How do I add extra ZFS swap in Solaris 11.3?

Hello, I have given 3 x 1 TB LUNs to add more swap space in a Solaris 11.3 OS -bash-4.4# swap -l swapfile dev swaplo blocks free /dev/zvol/dsk/rpool/swap 303,1 16 8388592 8388592 -bash-4.4# swap -s total: 84780376k bytes... (5 Replies)
Discussion started by: feroccimx
5 Replies

2. 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

3. 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... (7 Replies)
Discussion started by: vikas_trl
7 Replies

4. 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 ... (8 Replies)
Discussion started by: Lokesha
8 Replies

5. UNIX for Dummies Questions & Answers

To Add extra commas to a CSV file.

Hi All, I got this requirement to process a complex CSV file. Eg File. Line 1: Name:,XYz Line 2: Age:,15 Line 3: Grade:,7 Line 4: Line 5: English, Maths, Science,Spanish Line 6:10,11,13,14 As you can see the maximum column is 4 . The file i need to make is Line 1: Name:,XYz,,... (12 Replies)
Discussion started by: chillblue
12 Replies

6. 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! (2 Replies)
Discussion started by: tatchel
2 Replies

7. Shell Programming and Scripting

Single command for add 2 columns and remove 2 columns in unix/performance tuning

Hi all, I have created a script which adding two columns and removing two columns for all files. Filename: Cust_information_1200_201010.txt Source Data: "1","Cust information","123","106001","street","1-203 high street" "1","Cust information","124","105001","street","1-203 high street" ... (0 Replies)
Discussion started by: onesuri
0 Replies

8. 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... (4 Replies)
Discussion started by: smriti_shridhar
4 Replies

9. Linux

How to add and extra hour to the start time

Hi Actually what am trying to ask is , i have an shell script ,now i want to run this shell script for one hour continuously and after one hour it has to stop automatically. can any one suggest me how to automate the shell script ? we tried wth the getting the start time and add ing an hour... (8 Replies)
Discussion started by: lalitka
8 Replies

10. Shell Programming and Scripting

manipulating csv to add extra row

hi how do i manipulate .csv file to add an extra row after each row using shell script? I need a blank line added for each 1000 records in my file? I will then need to copy and paste some data in the blank row created. thanks 4 ur support neil (3 Replies)
Discussion started by: neil546
3 Replies
Login or Register to Ask a Question