Add extra columns help

Tags
beginners

 

 
Thread Tools Search this Thread
# 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.
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How do I add extra ZFS swap in Solaris 11.3? feroccimx Solaris 5 1 Week Ago 11:36 PM
Need to Insert three extra columns in csv file ahmed.vaghar Shell Programming and Scripting 5 09-13-2015 02:57 PM
Evaluate 2 columns, add sum IF two columns satisfy the condition Khushbu Shell Programming and Scripting 4 04-14-2015 10:21 AM
How to add extra spaces to make all lines the same length? Ophiuchus Shell Programming and Scripting 3 04-10-2015 02:11 PM
Request: How to Parse dynamic SQL query to pad extra columns to match the fixed number of columns vikas_trl Shell Programming and Scripting 7 01-22-2015 04:18 PM
Randomly inserting extra columns into csv file Lokesha Shell Programming and Scripting 8 09-20-2013 02:53 PM
Evaluate 2 columns, add sum IF two columns match on two rows mtucker6784 Shell Programming and Scripting 6 08-07-2013 01:57 PM
To Add extra commas to a CSV file. chillblue UNIX for Dummies Questions & Answers 12 07-05-2012 09:18 AM
To Add extra commas to a CSV file using 2 files... chillblue UNIX for Dummies Questions & Answers 1 07-05-2012 09:15 AM
how to add extra a field in a flat txt file ? britney Shell Programming and Scripting 5 04-13-2011 03:39 PM
Remove extra characters and sum the columns tatchel Shell Programming and Scripting 2 01-27-2011 08:40 PM
Single command for add 2 columns and remove 2 columns in unix/performance tuning onesuri Shell Programming and Scripting 0 07-01-2010 05:40 AM
how to flip values of two columns and add an extra column smriti_shridhar Shell Programming and Scripting 4 10-20-2008 06:36 AM
How to add and extra hour to the start time lalitka Linux 8 10-17-2008 06:52 PM
manipulating csv to add extra row neil546 Shell Programming and Scripting 3 07-16-2007 08:11 AM