LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-31-2013, 02:58 AM   #1
perumal07
LQ Newbie
 
Registered: Jul 2009
Posts: 19

Rep: Reputation: 0
Unhappy Script to export details to excel - URGENT


Dear Friends

I need your help on making a script as i am new to scripting.

i have a txt file which has the contents like below

username: test
email: test@test.com
emp ID: 11test
account: sbi
location: ban
sex: male
telep: 0000
....
etc


around 2 lines of a user information and the users are N numbers.

i have to fetch few days from this txt like username
email, emp id.

And the details should be placed in excel like below

username email emp id sex
test test@t 11test mail
xxxx xxxx xxxx xxxx
xxxx xxxx xxxx xxxx


Need your help
 
Old 12-31-2013, 03:19 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi and welcome to LQ

It isn't very clear from the above what it is you need/want.

- You show one input example and one output example. The output example has less fields than the input example.
- You mention around 2 lines of a user information. What is that supposed to mean.
- This is also unclear (what do you mean by days): i have to fetch few days from this txt like username
- Excel files are, in general, comma separated and your example is space separated.

Please describe in detail what it is you want/need otherwise you'll get answer that will not help you.

Also include what you have already tried.

BTW: Do not mark your threads as being urgent. It might be for you, but we are all volunteers here at LQ and it isn't urgent for us and we don't (try to) solve threads based on urgency.
 
1 members found this post helpful.
Old 12-31-2013, 03:43 AM   #3
perumal07
LQ Newbie
 
Registered: Jul 2009
Posts: 19

Original Poster
Rep: Reputation: 0
Question

Thank for the reply druuna

sorry its not days its datas

i have a userlog.txt file it has the rows like
username: test
email: test@test.com
emp ID: 11test
account: sbi
location: ban
sex: male
telep: 0000
....
etc


from this txt file i want to take particular informations like username, email, emp id, sex. out them to excel are csv formate as below.

username email emp id sex

test test@test.com 11test male
 
Old 12-31-2013, 03:51 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
We need more information:

- What does the input file look like. Post a larger portion, at least 3 full entries.
- Are username email emp id sex the only fields you want?

And use [code] ... [/code] around your examples. This will preserve the original layout.
 
Old 12-31-2013, 04:03 AM   #5
perumal07
LQ Newbie
 
Registered: Jul 2009
Posts: 19

Original Poster
Rep: Reputation: 0
Exclamation

Example of txt file :-


username: test
email: test@test.com
emp ID: 11test
account: sbi
location: ban
sex: male
telep: 0000
Department: it
country:IN


username: test1
email: test1@test.com
emp ID: 12test
account: icici
location: del
sex: fem
telep: 0001
Department: it0
country:IN


username: test2
email: test2@test.com
emp ID: 112test
account: sb2i
sex: mal2e
telep: 00200
Department: i2t
country:IN

username: test
email: test@test.com
emp ID: 11test
location: ban
sex: male
telep: 0000
Department: it
country:IN


From this i want to take only few like username, email id, and emp id if any information miss in data 0 should apply there.

output should be in excel username has the name, email id has email ids, and emp id should have employe code
 
Old 12-31-2013, 04:17 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by perumal07 View Post
From this i want to take only few like username, email id, and emp id if any information miss in data 0 should apply there.
What do you mean by missing?

- Is the complete entry missing? I.e.: sex: male is missing.
- Or is the value missing? I.e.: male is missing from the sex: entry.

Quote:
output should be in excel username has the name, email id has email ids, and emp id should have employe code
Are you sure you want the entries to be space separated and not comma separated (which is the standard way)?
 
Old 12-31-2013, 04:26 AM   #7
perumal07
LQ Newbie
 
Registered: Jul 2009
Posts: 19

Original Poster
Rep: Reputation: 0
Quote:

From this i want to take only few like username, email id, and emp id if any information miss in data 0 should apply there.
What do you mean by missing?

In that list some user will not have the entry sex: in that case 0 should apply in excel sheet

- Is the complete entry missing? I.e.: sex: male is missing.
its complete
- Or is the value missing? I.e.: male is missing from the sex: entry.

Quote:
output should be in excel username has the name, email id has email ids, and emp id should have employe code
Are you sure you want the entries to be space separated and not comma separated (which is the standard way)?

yes its comma separated so that i can get the datas in individual colum.

output should look like this

test1 | test1@test | 01test | male
test2 | test2@test | 02test | 0 if the files is missing
 
Old 12-31-2013, 04:43 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You are all over the place with the answers you are giving and they contradict each other as well.

Quote:
Originally Posted by perumal07 View Post
- Is the complete entry missing? I.e.: sex: male is missing.
its complete
- Or is the value missing? I.e.: male is missing from the sex: entry.
So you are saying that the following entry might be present:
Code:
username: test1
email: test1@test.com
emp ID: test1
account: test1
location: test1
telep: test1
Department: it
country:IN
The above is missing the sex entry OR is it like this:
Code:
username: test1
email: test1@test.com
emp ID: test1
account: test1
location: test1
sex:
telep: test1
Department: it
country:IN
The value for sex is missing.

Quote:
output should be in excel username has the name, email id has email ids, and emp id should have employe code
Are you sure you want the entries to be space separated and not comma separated (which is the standard way)?

yes its comma separated so that i can get the datas in individual colum.

output should look like this

test1 | test1@test | 01test | male
test2 | test2@test | 02test | 0 if the files is missing
This doesn't make sense whatsoever!!

The output can look like this (comma separated):
Code:
test1,test1@test.com,test1,test1
OR space separated:
Code:
test1 test1@test.com test1 test1
OR pipe separated:
Code:
test1|test1@test.com|test1|test1
I also notice that:
- some entries do not have a space between the fields: country:IN Is this a typo or are these actually present?
- Some fields start with a capital: Department: it Are the fields always written the same way or is the following entry also possible: department: it

Answer the questions in detail otherwise we are not able to help you.

And I told you before to use [code] [/code] tags around the examples you post!
 
Old 12-31-2013, 12:30 PM   #9
yo8rxp
Member
 
Registered: Jul 2009
Location: Romania
Distribution: Ubuntu 10.04 Gnome 2
Posts: 102

Rep: Reputation: 31
well try to put some delimiters between inputs then use variables in a script

username=$(cat file.txt | grep "username" | sed 's/.* //g)
this is just an example , you could put delimiters inside that file , grep | wc -l how many entries , then loop for entries in $(how many); get values from first to next entry , and grep there for variables like above.

then using csv u can echo >> towards another file echo $username","$email"," >> new_file.csv

make a folder and a shell script run.sh containing
Code:
#!/bin/bash
rm new.csv
rm tmp.file
## Begin header ##
echo "username","email","emp_ID" > new.csv
## End header

function search {
## Add here next variables , have to substitute values ###
username=$(cat tmp.file | grep "username" | sed 's/.* //g') 
email=$(cat tmp.file | grep "email" | sed 's/.* //g') 
emp_id=$(cat tmp.file | grep "emp ID" | sed 's/.* //g') 

## Populate new file rows ##
echo $username" "$email" "$emp_id >> new.csv 
} 

lenght=$(cat file.txt |wc -l)
for line in `seq 1 $lenght`
do
if [ "$(sed ''$line'!d' file.txt)" != "" ] ; then echo $(sed ''$line'!d' file.txt) >> tmp.file ;  else  search ;  echo "" > tmp.file
fi
echo $line
done
rm tmp.file
put that text file in same folder
make run.sh executable and run it
only username and email was added for example , you can add more identically.
this is what i got running my script
In this case , the delimiter itself is the gap ( empty rows ) between entries, gaps detected and used to restart search in the next block
Code:
username email emp_ID
test test@test.com 11test
  
test1 test1@test.com 12test
  
test2 test2@test.com 112test
Good luck hacking database


P.S. druuna is right ! aint polite to mark it as URGENT .. Concider this as a christmass / new year eve gift

sincerely ,
Gabriel linux-romania.com

Last edited by yo8rxp; 12-31-2013 at 02:27 PM.
 
1 members found this post helpful.
Old 01-02-2014, 12:48 PM   #10
perumal07
LQ Newbie
 
Registered: Jul 2009
Posts: 19

Original Poster
Rep: Reputation: 0
Thank you so much brother but everything executed pls help me out and here i will give u one permission



# name perumal
cn: Perumal
company: test
displayName: Pandey
facsimileTelephoneNumber: 100
givenName: ndra
l: Indofil
mail: perumal@gmail.com
ou: Super
pager: 4A
sn: Pandey
street: costal
uid: perumal
AccountStatus: active
Id: 4bc494e8-ce96-4b21
ContactEmailFields: email,email2,email3,email4,email5,email6,email7,email8,email9,email10,workEmail1,workEmail2,workEmai l3

# name perumal
cn: Perumal
company: test
displayName: Pandey
facsimileTelephoneNumber: 100
givenName: ndra
l: Indofil
mail: perumal@gmail.com
ou: Super
pager: 4A
sn: Pandey
street: costal
uid: perumal
AccountStatus: active
Id: 4bc494e8-ce96-4b21
ContactEmailFields: email,email2,email3,email4,email5,email6,email7,email8,email9,email10,workEmail1,workEmail2,workEmai l3


# name perumal
cn: Perumal
company: test
displayName: Pandey
facsimileTelephoneNumber: 100
givenName: ndra
l: Indofil
mail: perumal@gmail.com
ou: Super
pager: 4A
sn: Pandey
street: costal
uid: perumal
AccountStatus: active
Id: 4bc494e8-ce96-4b21
ContactEmailFields: email,email2,email3,email4,email5,email6,email7,email8,email9,email10,workEmail1,workEmail2,workEmai l3




pls give me script for this it will be more helpful
 
Old 01-02-2014, 01:21 PM   #11
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@perumal07: What needs to be done with this? It doesn't look at all like your earlier examples.

You seem to be having a very hard time explaining to us what it is you want, even though I've asked multiple times already.

If you dump some data and ask for a script without any explanation nobody will be able to help you.
 
1 members found this post helpful.
Old 01-02-2014, 01:36 PM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,731

Rep: Reputation: 7973Reputation: 7973Reputation: 7973Reputation: 7973Reputation: 7973Reputation: 7973Reputation: 7973Reputation: 7973Reputation: 7973Reputation: 7973Reputation: 7973
Quote:
Originally Posted by perumal07 View Post
Thank you so much brother but everything executed pls help me out and here i will give u one permission

pls give me script for this it will be more helpful
We will be very happy to HELP YOU with a script...but we are NOT going to write one for you. If you want someone to write programs for you, post this job in the LQ Job marketplace (along with how much you're willing to PAY to have your work done for you), and I'm sure you'll get it done quickly.

Otherwise, please spell out your words, and post what you've written/tried so far. You've been given MANY examples/samples thus far, and should be able to modify those examples to work for you.
 
Old 01-02-2014, 01:37 PM   #13
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
well to use Microsoft's Excel
you NEED microsoft Office
and to run the current Microsoft Office , you NEED to be running Windows 7
or
win8 with office365

so
you need to use Microsoft's Visual Basic on a windows computer
or Perl,python on a windows computer

or


use Openoffice's "Calc"
but
using Microsoft's proprietary *.docx" format is NOT recomended

use openoffice format .sxc


as to "a script"
a python one would be able to easily convert the "text files" to a CSV file
then it is a very simple matter to import the csv file into OO's calc.

Last edited by John VV; 01-02-2014 at 01:39 PM.
 
Old 01-02-2014, 02:30 PM   #14
yo8rxp
Member
 
Registered: Jul 2009
Location: Romania
Distribution: Ubuntu 10.04 Gnome 2
Posts: 102

Rep: Reputation: 31
sorry but i just made ya a free gift. power is where knoledge is...therefore stop wasting your and other good ppl time. it is simply not fair!
made and tested that script for ya in 20 minutes. it simply works !
all u got to do was to add multiple rules as i explained into script.
shame on you !

Last edited by yo8rxp; 01-02-2014 at 11:15 PM.
 
1 members found this post helpful.
Old 01-02-2014, 03:18 PM   #15
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by druuna View Post
...
- Excel files are, in general, comma separated and your example is space separated.
...
excel files are proprietary binary format (although ms-excel can also read csv files which are ascii text seperated by commas).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I need details about export command and how to use it linuxpandi Linux - Newbie 3 01-25-2012 02:10 AM
How to export reports generated in Linux to excel sheets. sumitdevbharadwaj Programming 4 12-29-2008 11:18 PM
export data to excel or oenoffice.org using Qt pragnya Linux - General 1 01-20-2006 04:55 AM
Export MySQL table into MS Excel spreadsheet dr_sad Programming 1 07-06-2005 12:56 PM
very urgent!details about execve()??????? vrdhananjay Programming 11 02-08-2005 05:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration