'for LINE in $(cat file)' breaking at spaces, not just newlines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 'for LINE in $(cat file)' breaking at spaces, not just newlines
# 8  
Old 08-18-2011
There's another reason now I'd much prefer someone to just tell me how to edit the python script, but going by the thread's title, I don't think we'd be getting anyone from python over here.

Though I doubt Clear Channel Communications would do something like that, I suppose THEY could be hacked and that would happen. Or even random data corruption could wreak havoc.
# 9  
Old 08-18-2011
Quote:
Originally Posted by natedawg1013
There's another reason now I'd much prefer someone to just tell me how to edit the python script, but going by the thread's title, I don't think we'd be getting anyone from python over here.
If I knew Python I'd try it. The language being Python, I suspect it's a brute-force approach anyway: import magic-xml-library; stuff=magic-xml-load("file.xml"); print(stuff);

There's tons and tons of libraries to do this, but nothing easy. It all becomes modular tree-walking multi-callback nonsense which kind of rules out a nice-looking script taking less than a page. I've been trying for a while to come up with something better, but as you might figure by now, it's a far harder problem than it looks.
# 10  
Old 08-19-2011
Quote:
Originally Posted by natedawg1013
There's another reason now I'd much prefer someone to just tell me how to edit the python script...
Perhaps this will help you get started:

Code:
$ cat foo.xml
<foo a="1">
    <bar b="2" c="Some string">
    </bar>
</foo>

Code:
$ cat foo.py
from xml.etree.ElementTree import ElementTree
t = ElementTree()
t.parse('foo.xml')
print t.find('bar').get('c')

Code:
$ python foo.py
Some string


Regards,
Alister

---------- Post updated at 11:44 PM ---------- Previous update was at 11:32 PM ----------

A slightly more useful example:
Code:
 cat foo.xml
<foo a="1">
    <bar b="1" c="Some string">
    </bar>
    <bar b="2" c="Another string">
    </bar>
    <bar b="3" c="One last string">
    </bar>
</foo>

Code:
from xml.etree.ElementTree import ElementTree
t = ElementTree()
t.parse('foo.xml')
for b in t.findall('bar'):
        print '%s: %s' % (b.get('b'), b.get('c'))

Code:
$ python foo.py
1: Some string
2: Another string
3: One last string

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 11  
Old 08-19-2011
Thank you for the replies, but if working in python from the original script, getting the information from the XML is already set up. What I'd need now is help with the other annoyances like setting up command-line arguments, etc. in my starred list. Otherwise, I'll do some research and get back to you guys with the final result.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed a multiple line pattern that has newlines followed by text and r

Here is the text that I was to run sed on. In this text I want to insert a semi colon ';' before 'select a13.STORE_TYPE STORE_TYPE,' and after 'from ZZMR00 pa11' Input text: insert into ZZMQ01 select pa11.STATE_NBR STATE_NBR, pa11.STORE_TYPE STORE_TYPE, ... (9 Replies)
Discussion started by: v_vineeta11
9 Replies

2. UNIX for Dummies Questions & Answers

Sendmail with cat adding extra spaces in email body

when I try to read a file and send email using cat and sendmail: The email received having additional spaces.(Between the letters of words in the text) My code: export MAILTO="sa@y.com" export SUBJECT="mydomain PREPROD MONITOR AT ${DATE}" export... (5 Replies)
Discussion started by: visitsany
5 Replies

3. AIX

Script to cat and dd last line!!! of each file

hi Guys, Am new to this awesome forum, and yea i need some help here asap thnx :) i have a directory with over 34000 text files, i need a script that will delete the last line of each of this file without me necessary opening the files. illustration:- file1 200 records file2 130 records... (5 Replies)
Discussion started by: eetang
5 Replies

4. Shell Programming and Scripting

sed remove newlines and spaces

Hi all, i am getting count from oracle 11g by spooling it to a file. Now there are some newline characters and blank spaces i need to remove these. pl provide me a awk/sed solution. the spooled file is attached. i tried this.. but not getting req o/p (6 Replies)
Discussion started by: rishav
6 Replies

5. Shell Programming and Scripting

split a line of a file and cat a file with another

Hi, I have two files one.txt laptop boy apple two.txt unix linux OS openS I want to split one.txt into one line each and concatenate it with the two.txt output files onea.txt laptop (4 Replies)
Discussion started by: avatar_007
4 Replies

6. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

7. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

8. Shell Programming and Scripting

Breaking line

My input file is like USER_WORK.ABC USER_WORK.DEF I want output file like ABC DEF (4 Replies)
Discussion started by: scorp_rahul23
4 Replies

9. UNIX for Dummies Questions & Answers

newb help! file name with spaces breaking up when trying to retrieve it

for file in `ls *.txt` do sed '/s/old/new/g' $file > /tmp/tempfile.tmp mv /tmp/tempfile.tmp $file done the txt files names look like "text file one.txt", "text file two.txt" but when I run it, all i get is: sed: 0602-419 Cannot find or open file text. sed: 0602-419 Cannot find or... (3 Replies)
Discussion started by: DeuceLee
3 Replies

10. Shell Programming and Scripting

Cat'ing a multiple line file to one line

I am writing a script that is running a loop on one file to obtain records from another file. Using egrep, I am finding matching records in file b, then outputing feilds of both into another file. **************************** filea=this.txt fileb=that.txt cat $filea | while read line do... (1 Reply)
Discussion started by: djsal
1 Replies
Login or Register to Ask a Question