how to convert fields from a text file to excel columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to convert fields from a text file to excel columns
# 1  
Old 12-22-2008
how to convert fields from a text file to excel columns

i have this file which has the following contents:

Code:
,-0.3000   ,-0.3000   ,-0.3000
,-0.9000   ,-0.9000   ,-0.9000

i would like to get this:
Code:
 
-0.3-0.9-0.3-0.9-0.3-0.9

so far i am trying:

Code:
awk '{for(i=1; i<=NF; i++) {printf("%f\n",$i)}}' test1 > test2

any help appreciated.
# 2  
Old 12-22-2008
Code:
sed -e '$!N' -e 's/ *,\([-]*[0-9]\.[0-9][1-9]*\)[0]*/\1/g' -e 's/\n//g'

or completing the awk version (untested)
Code:
awk -F, '{for ( i=1;i<=NF;i++) {printf "%.1f",$i}}'

# 3  
Old 12-22-2008
sorry that didnt print right..

i want this :

-0.3 -0.9
-0.3 -0.9
-0.3 -0.9
# 4  
Old 12-22-2008
That is not the same as what you asked for in the original post.

Try any of the solutions in the search below, any of the awk options will work, and all you will have to do is update the print/prtinf formatting:

Search "transpose" on UNIX.COM
# 5  
Old 12-23-2008
thanks for your help..

i ended up using:

Code:
paste -d ',' file1 file2 > out.csv

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert text to columns

Hi. I need an input file of a single word pr. line converted in into a list of random pairs. i need input like this word1 word2 word3 word4 to be outputted like this: word3 word1 word2 word4 My attempt is a tedious while loop like this: nfiles=$(cat inputfile | wc -l) ... (4 Replies)
Discussion started by: BotHead
4 Replies

2. UNIX for Beginners Questions & Answers

Convert Excel File (xls) to tab delimited text file on AIX

Hi i have a problem in my job i try to convert an excel file (xls extention) to text file (tab delimited), but no result with this comand cat xxx.xls > xxx.txt Do you have eny idea? PS: sorry for my english Thanks!! (4 Replies)
Discussion started by: frisso
4 Replies

3. Shell Programming and Scripting

Need help to write a shell script to convert text file to excel file.

Hi Everyone, I want your help to write a script which will take text file as input and on the basis of delimiter ":"script will create excel sheet. Example input: IpAdress:InstanceName:Port:ServerName 10.255.255.1:abc:2232:xyz_abc Output should be an excel sheet like below: Column... (8 Replies)
Discussion started by: akabhinav18
8 Replies

4. Shell Programming and Scripting

Need to convert text file into Excel sheet

:cool:Hi, Iam new to this Scripts and forum too. Plz excuse if may i ask silly questions now and further.. Prob: i need to convert txt files data into excel sheet. Suppose if i have hour-wise data in txt file1 and file2 like file1 file2 00: 140 00: 235 01: 160 01:415... (1 Reply)
Discussion started by: mrudula
1 Replies

5. Shell Programming and Scripting

Need to convert delimited text file in UNIX to an Excel file

Dear Users , Need to convert delimited text files in UNix server to an Excel file and move the excel file to Windows environment. Am trying to automate the whole process. Can anyone share the ideas,if they have done similar ones before...Thanks -Meera (1 Reply)
Discussion started by: meerakrish
1 Replies

6. Shell Programming and Scripting

How to convert excel file to csv file or text file?

Hi all, I need to find a way to convert excel file into csv or a text file in linux command. The reason is I have hundreds of files to convert. Another complication is the I need to delete the first 5 lines of the excel file before conversion. so for instance input.xls description of... (6 Replies)
Discussion started by: johnkim0806
6 Replies

7. Shell Programming and Scripting

Deleting all the fields(columns) from a .csv file if all rows in that columns are blanks

Hi Friends, I have come across some files where some of the columns don not have data. Key, Data1,Data2,Data3,Data4,Data5 A,5,6,,10,, A,3,4,,3,, B,1,,4,5,, B,2,,3,4,, If we see the above data on Data5 column do not have any row got filled. So remove only that column(Here Data5) and... (4 Replies)
Discussion started by: ks_reddy
4 Replies

8. UNIX for Dummies Questions & Answers

How to convert text to columns in tab delimited text file

Hello Gurus, I have a text file containing nearly 12,000 tab delimited characters with 4000 rows. If the file size is small, excel can convert the text into coloumns. However, the file that I have is very big. Can some body help me in solving this problem? The input file example, ... (6 Replies)
Discussion started by: Unilearn
6 Replies

9. UNIX for Advanced & Expert Users

how to convert text/csv to excel

Hello All, I have a sql report with 50 columns and 1000 rows result in a file ( txt / csv). is there is any way that we can move them to excel in KSH. Thanks, Sateesh (7 Replies)
Discussion started by: kotasateesh
7 Replies

10. Shell Programming and Scripting

convert Text to Excel

I have some text data generated by a perl script and want to put it into an excel sheet. Is there a perl script that can do this for me, i.e, convert text data to excel? (1 Reply)
Discussion started by: Pavankk
1 Replies
Login or Register to Ask a Question