need a text parser


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need a text parser
# 1  
Old 07-29-2008
Question need a text parser

i need a simple text parser which can parse a data file created by a softwre so that i can export it to my mysqldb,, datafile created as one record per line with different number of fields.
e.g datafile contains following.
a=1, b=3, c=4
a=1, c=55, d=abcd
a=5, b=hello, c=99, d=help

now i want to parse them as
1,3,4
1,55,abcd
5,hello,99,help
i want to remove field name and make data as comma seperated so that i can export them to my db. or anyother way to export these fields to mysql where field names are same as a,b,c,d.
a,b,c and d are fields.
# 2  
Old 07-29-2008
Quote:
Originally Posted by sfaizan
i need a simple text parser which can parse a data file created by a softwre so that i can export it to my mysqldb,, datafile created as one record per line with different number of fields.
e.g datafile contains following.
a=1, b=3, c=4
a=1, c=55, d=abcd
a=5, b=hello, c=99, d=help

now i want to parse them as
1,3,4
1,55,abcd
5,hello,99,help
i want to remove field name and make data as comma seperated so that i can export them to my db. or anyother way to export these fields to mysql where field names are same as a,b,c,d.
a,b,c and d are fields.
Code:
cat datafile | sed 's/[^,]*=//g'

# 3  
Old 07-30-2008
thnx BMDan it realy works. i used it (sed) with awk in bash script instead of cat and got the data i wanted.

one more question in the folder thr are many data files created daily named e.g data20080729_0000. one or two files created daily. i want to use the bash script so that i chk the folder for all files named data***** parse them and at the end move them to other folder. makeing the current folder empty.
# 4  
Old 07-30-2008
Quote:
Originally Posted by sfaizan
thnx BMDan it realy works. i used it (sed) with awk in bash script instead of cat and got the data i wanted.

one more question in the folder thr are many data files created daily named e.g data20080729_0000. one or two files created daily. i want to use the bash script so that i chk the folder for all files named data***** parse them and at the end move them to other folder. makeing the current folder empty.
If your script is named "my_parser_script.sh":
Code:
for file in $(ls -1d data*); do ./my_parser_script.sh "$file"; mv $file archive/; done

For future questions, please specify the meanings of "parse" and "other folder", though I've made assumptions here.

Lastly, if I may offer a suggestion--train yourself to type carefully and well. If you type things like "thnx", "realy", "thr", "chk", and "makeing", imagine what mistakes like that would translate to on a *NIX command line! Double the amount of time you budget for a reply, type more slowly, and read what you wrote. By taking things a little more slowly on these forums, you'll quickly discover you learn a lot more, too, and you'll sometimes discover that you know the answer to your question already when you've taken the time to carefully describe it. For example, there is another way to accomplish this that I'd bet you could have come up with:

Code:
ls -1d data* | xargs -n 1 ./my_parser_script.sh; mv data* archive/

At any rate, enough lecture. It just saddens me to see people who work in a discipline in which the difference between rm -rf and rm -f is so large being so careless with what's coming out of their keyboard.
# 5  
Old 07-30-2008
Thank you. I appriciate. basically i am not a programmer. I am trying to solve this because of my own ease for things I have to do manualy everyday. But I appriciate your help.
One problem I didnt notices. When using AWK and SED i get the desired results on screen. But when I put ' >> filename ' at the end so that the results goes to a specific file, in that file i get trailing '\' after comma in every field.
e.g
1\,3\,4
1\,55\,abcd
5\,hello\,99\,help
# 6  
Old 07-30-2008
Not seeing what actually you you're doing is making it hard to help...
Help us to help you......
# 7  
Old 07-30-2008
pealse read my first post. I want to change the data file created by a sofware to the simple one. by removing the left side of '=' and keeping the right side. one line per record to a new datafile. All are text files. I am using awk in bash with sed to remove the '=' and left side. but output in screen is ok, but in bash script if i try to use '>> newfilename' it adds '\' (back slash) at the end of each comma seperated field. I dont know may be its blank or empty space which is shown as '\' or something else.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Making a parser

input 1..100km 112..403km 500..623km required output 1..51 112..162 500..550 (i.e 50kms added to the initial distance) (2 Replies)
Discussion started by: ANKIT ROY
2 Replies

2. Shell Programming and Scripting

Parser

Hi All, I am trying to create a parser to find out what cobol programs are being called by which JCL's. I need to search recursively until the main cobol program is found being called by a JCL. I tried to create a script but I am not able to generalize it. Can someone please help. ... (1 Reply)
Discussion started by: nua7
1 Replies

3. Shell Programming and Scripting

SQL Parser

Hi, I have been assigned a task to migrate few thousands of sql scripts to a different db format. there could be sub queries and complex joins. there would be functions that needs to be replaced from a given list to another values. this should also parse the sub\inline queries. Can you please... (1 Reply)
Discussion started by: hitmansilentass
1 Replies

4. Shell Programming and Scripting

File Parser

Hi need help parsing a file. I have tag fields and values in a file with delimiter |. sample records from the file listed below 8=value|9=value|35=value|49=value|56=value|34=value|50=value|48=value|10=value 8=value|9=value|35=value|49=value|56=value|34=value|51=value|48=value|10=value... (2 Replies)
Discussion started by: subramanian
2 Replies

5. Programming

Parser

Hi Everyone I have an out put of multiple lines which I would like to parse and retrieve certain info from it. The output consists of multiple sections that starts with the line Client: and ends with STL tag: each section separated by an empty line. So basically somehting like Client: ... (10 Replies)
Discussion started by: bombcan1
10 Replies

6. Shell Programming and Scripting

Parser with sed

Hi, I have this variable: <a href="http://www.rtve.es/mediateca/videos/20100916/video-calamares-rellenos-salsa-pimientos-garbanzos-16-09-10/878586.shtml">V�deo: Calamares rellenos con salsa de pimientos y ...</a> I would like to have: ... (7 Replies)
Discussion started by: mierdatuti
7 Replies

7. Shell Programming and Scripting

Incremental log parser

I have log file that is incremented every second and is rather big. I need monitor error in this file. I do not want to parse it all every time. I want parse it first time then remember last position (as byte for example) All consequent parsing I want to start from last saved position to the... (3 Replies)
Discussion started by: Narcom
3 Replies

8. Shell Programming and Scripting

Help with an (easy) parser

Hello, i'm workig with a file with structural information about biological macromolecules (proteins etc). In a certain file, the info is structured like this @<TRIPOS>MOLECULE blah 1 blah 2 blah 3 @<TRIPOS>MOLECULE foo 1 foo 2 foo 3 @<TRIPOS>MOLECULE mmm 1 mmm 2 mmm 3 I would... (7 Replies)
Discussion started by: aristegui
7 Replies

9. Shell Programming and Scripting

Text Parser

I am having a text file as follows say server.txt Date Time server ip error code -------------------------------------------------------------------------- 02/21/2008 18:10:14 server1 xxx.xxx.xxx.xxx 6 02/21/2008 08:10:14 server2 ... (8 Replies)
Discussion started by: karthikn7974
8 Replies

10. Shell Programming and Scripting

string parser

I am new to scripting I want to parse a string in a loop eg A:B:C:D E:F:G:H and put them in different variable attr1 = A attr2 = B attr3 = C attr4 = D . . /* do processing with attr1, attr2, attr3 and attr4 */ then go to next line E:F:G:H and again assign... (8 Replies)
Discussion started by: flextronics
8 Replies
Login or Register to Ask a Question