How to write text file data to excel using UNIX shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to write text file data to excel using UNIX shell script?
# 8  
Old 06-24-2013
What be so difficult in using code tags as required?

If I interpret correctly what you say, those country/currency entries already exist in output.xls. Be aware that correlating file entries based on just line numbers may be dangerous as a missing line will corrupt your results. Anyhow, try sth like (untested):
Code:
awk 'NR==FNR {TMP[NR]=$6"|"$7"|"$8"|"$9; next} FNR==1 {print "Col1|Col2|Col3|Col4|Col5|Col6";next} {print $1"|"$2"|"TMP[NR]} output.xls Inputdata.txt

Edit: Improved above untested version:
Code:
awk     'FNR==NR        {TMP[FNR]=$6"|"$7"|"$8"|"$9; next}
         FNR==1         {print "Col1|Col2|Col3|Col4|Col5|Col6";next}
                        {print $1"|"$2"|"TMP[FNR]}
        ' InputData.txt output.xls
Col1|Col2|Col3|Col4|Col5|Col6
IND|INR|May|13|12:27|TestMurex
IND|INR|May|13|12:29|20130614
IND|INR|Jun|13|08:43|Markt3
US|USD|Jun|13|09:22|Markt2
EUR|EUR|Jun|13|09:22|Markt1
EUR|EUR|Jun|14|15:01|Markt
AUS|AUD|Jun|24|10:59|..
GBP|GBP|Jun|24|11:07|Inputdata.txt
GBP|GBP|Jun|24|11:07|.


Last edited by RudiC; 06-24-2013 at 01:08 PM.. Reason: eliminated script errors and tested it.
# 9  
Old 06-24-2013
Thanks for your quick response Pikk

But her the out put is going in to single column in excel,i need each word should place in each cell of the excel say in A1 cell Column1 and B1 column2 .....etc and in A2 cell IND,B2 cell INR ...etc.

Please help me !!!
# 10  
Old 06-24-2013
Try the delimiter as TAB. that should help you!
# 11  
Old 06-25-2013
One option is to just copy-paste the ls -ltr output into excel, it gets pasted into a single column (with a selection band around it). Without doing any else, just go straight to the menu and choose data -> text to columns -> delimited -> and select space and tab as separator and select treat consecutive delimiters as one and then choose next and finish. If there are no spaces in your file names then the ls output should land nicely in seperate columns.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

2. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 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

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

5. Shell Programming and Scripting

Shell Script for copying text file to Excel Sheet

Hi, I want to write a program to copy a log file to Excel sheet. Excel sheet has four columns MethodName , Code , Description, Details and Time. I want to pick these info from text file and put it in excel sheet. here is how the text file looks - 04.17.2014 08:06:12,697... (1 Reply)
Discussion started by: hershey
1 Replies

6. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies

7. Shell Programming and Scripting

Need help on inserting data from text file to excel using shell script

Hi, Please help me on this. I want to insert data from text file to excel using shell script nawk -v r=4 -v c=4 -v val=$a -F, 'BEGIN{OFS=","}; NR != r; NR == r {$c = val; print}' "file.csv" I used above one to insert $a value in 4th row, 4th column in an excel file.csv and it... (3 Replies)
Discussion started by: suman.frnz
3 Replies

8. Shell Programming and Scripting

a shell script to generate an excel sheet from a text file..

hi, i have a text file that looks like this! i want to generate an excel sheet out of it, removing all the junk data except the addresses that look like . Arrow Electrical Services Rotating Machinery, Electrical Contracting & Mining Specialists Onsite maintenance, breakdown... (8 Replies)
Discussion started by: vemkiran
8 Replies

9. UNIX for Advanced & Expert Users

put data in excel file using shell script

Hi. I wish to add data in a specific excel file on daily basis.However the currect dat's data should always come on top i.e for example should always occupy cell A7,B7,C7 .. and the data of day before which was earlier on 7th row of each coloumn should move to 8th row..data on 8th row should... (1 Reply)
Discussion started by: kanus
1 Replies

10. Shell Programming and Scripting

how to put data using shell script to a excel file

Hi, Can any one tell me how to put data using shell script to a excel file from text file to other columns of excel file,leaving first column unaffected i.e it should not overwrite data in first column. Say my text file data is: 15-dec-2008 15-dec-2009 16-dec-2008 16-dec-2009 say my first... (1 Reply)
Discussion started by: siri_886
1 Replies
Login or Register to Ask a Question