LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-01-2005, 09:10 AM   #1
Grafbak
Member
 
Registered: Jun 2003
Location: /dev/null
Distribution: Knoppix 3.3
Posts: 61

Rep: Reputation: 15
question about grepping something


Hello all,

i am trying to split up an xml file, and i want to use the grep command to do so.
My problem is that when i do this :

grep -n "</bf:log>" ev_14567-20050215_0956.xml

that i get an out put like this :

2404628:</bf:log>

Because i want to do some calculations in a script with the rule-number (for using head and tail), i need the output to be this :

2404628

So actually i just wanna chop off the ":</bf:log>" piece. (and be able to use 2404628 as a numerical value in a script)
I have looked in the forums, and i saw that the awk command was advised, but after trying for a while i can not get the output the way that i want it.
Can someone please give me a hand ?

Thank you very much.
 
Old 03-01-2005, 09:16 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175
grep blah | cut -f 1 -d:
 
Old 03-01-2005, 09:17 AM   #3
Grafbak
Member
 
Registered: Jun 2003
Location: /dev/null
Distribution: Knoppix 3.3
Posts: 61

Original Poster
Rep: Reputation: 15
Thanks a lot ! It's working !! (ofcourse it is you'll think )
 
Old 03-01-2005, 09:27 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175

Doh!!
even simpler....

grep -l
(minus ell)
 
Old 03-01-2005, 01:39 PM   #5
Grafbak
Member
 
Registered: Jun 2003
Location: /dev/null
Distribution: Knoppix 3.3
Posts: 61

Original Poster
Rep: Reputation: 15
I hope u can help me with the following as well if i may ask.

I have a list of xml files that need to be parsed by a Java parser (from selectbf).
When the files are too big it does not funtion anymore.
So i decided to write a "tiny" "easy" bash-script that would split up the xml-files and make sure all the tags are correct.
Now, on paper it looks pretty good, i've got it all worked out. I only need a piece of code ( )

My current problem is that i have 3 xml files in a directory :

-rw-r--r-- 1 grave grave 129800403 Mar 1 18:19 ev_14567-20050215_0956.xml
-rw-r--r-- 1 grave grave 4305438 Mar 1 18:19 ev_14567-20050218_2158.xml
-rw-r--r-- 1 grave grave 2109 Mar 1 18:19 voorbeeld_part1.xml

The criterium for a file to be split up into smaller ones is 30 MB. So if it is bigger than 30 MB it needs to be copied to a special directory where the splitting process will take place.
However i can't get my loop in bash working correctly since it moves all the xml-files instead of just the one from 129 mb.

Here is my code :

#!/bin/bash
#This script will (try to) split xml-logfiles from BF1942 into decent, usable ones of 30 mb in size.
#detection of how many xml-files we have that are bigger than 30 MB cause they need to be split up
#how many xmlfiles are in the directory to start with ?
#First we set all variables to zero, just making sure
number_of_xmlfiles=0
filesize_kb=0
filesize_lines=0
filesize_limit_kb=30000
filename_bigxml=0
filename_anyfile=0
path_to_all_xmlfiles="/home/grave/download/logs/xmltest/"
dest_path_big_xmlfiles="/home/grave/download/logs/xmltest/test2"
ftp_url="ftpserver"
ftp_pass="password"
ftp_user="username"
i=0
#here is some room for the ftp-procedure
wget ftp://username:password@ftpserver_ur...942/logs/*.xml
#lets make a textfile that contains all the xmlfiles, big and small, just to see how many we got
listing=`ls /home/grave/download/logs/xmltest/*.xml`
echo "$listing">listing.txt
#and echo it out as a check, we can remove or comment this later, right now its usefull for error handling
echo "$listing"
#how many xml files do we have exactly
number_of_xmlfiles=`wc -l listing.txt|cut -f1 -dl`
echo "$number_of_xmlfiles"
# Next we're gonna copy all xml files bigger than 30 mb to a separate (parsing) directory
# However we need to define the xml file that the script is currently looking at :

while [ "$i" -le "$number_of_xmlfiles" ] && [ "$filesize_kb" -gt "$filesize_limit_kb" ];
do
current_filename=`head -n "$i" listing.txt` # RIGHT HERE IT GOES WRONG
echo "$current_filename"
echo "$i"
echo "$number_of_xmlfiles"
echo "$filesize_kb"
echo "$filesize_limit_kb"
mv "$path_to_all_xmlfiles"/*.xml "$dest_path_big_xmlfiles"/
echo dit lijkt goed te gaan
i=$(($i+1))
done
#filesize_lines=`wc -l |cut -f1 -de` #this is for later on, neglect it for now
echo $filesize
exit


I have tried to comment it as good as possible, and the programming might be just a 'bit' crappy, but please if someone can tell me what is wrong with my loop, i'm all ears. The splitting of the files is something i will have to deal with later on. I try to take one step at a time.

If someone has time, please let me know what im doing wrong here.
 
Old 03-01-2005, 02:25 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
I didn't want to try and debug the loop

How about this?

find -size +30000k -exec mv {} /home/grave/download/logs/xmltest/test2/. \;
 
Old 03-01-2005, 02:28 PM   #7
Grafbak
Member
 
Registered: Jun 2003
Location: /dev/null
Distribution: Knoppix 3.3
Posts: 61

Original Poster
Rep: Reputation: 15
i just found it

Guess i've been staring at it for too long.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to access IP addresses when grepping ecampos02 Linux - General 1 11-05-2005 03:39 PM
grepping unknown text, is there a way? vdemuth Programming 15 09-26-2005 04:00 AM
grepping last word of output rajatgarg Programming 3 11-25-2003 11:41 AM
Not grepping emails right mikeyt_333 Linux - General 11 04-13-2003 03:48 PM
grepping for multi-line output born4linux Programming 1 03-07-2003 03:26 AM


All times are GMT -5. The time now is 05:11 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration