Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (4) </ 1 2 [3] 4 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Little help needed, Bash scripting< Next Oldest | Next Newest >
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Jan. 31 2007,22:01 QUOTE

Heh, what happens if you put double quotes around the outer cat?

Personally, I'd just use IFS - it's easy to do and read.
Back to top
Profile PM 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Feb. 01 2007,05:38 QUOTE

Quote (^thehatsrule^ @ Jan. 30 2007,16:09)
If you plan on using sed, you could use "s/ /\ /g"
If you plan on using a shell script, you could use IFS
(i.e.
IFS="
"
or use 'read')

Or you could just remember to never use spaces in filenames :P

I don't understad this...
You are creating a variable here containing only one return char?

EDIT
Quote
      read  [-ers]  [-u  fd] [-t timeout] [-a aname] [-p prompt] [-n nchars]
      [-d delim] [name ...]
             One  line  is  read  from  the standard input, or from the file
             descriptor fd supplied as an argument to the -u option, and the
             first  word  is  assigned to the first name, the second word to
             the second name, and so  on,  with  leftover  words  and  their
             intervening separators assigned to the last name.  If there are
             fewer words read from the input stream than names, the  remain-
             ing names are assigned empty values.  The characters in IFS are
             used to split the line into words.  The backslash character (\)
             may  be used to remove any special meaning for the next charac-
             ter read and for line continuation.


Now I may know what you mean...


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Feb. 01 2007,05:53 QUOTE

It worked just fine.
But. I'd like to have it on one line.
So I did this:
Code Sample
IFS=`echo -e "\n"` && cat `echo -e "one two three\nfour five six\nseven" | sed -e 's/ /\\ /g'`

Now It should work but it ain't. =D
It tells me:
Quote
cat: one two three
four five six
seven: No such file or directory

When it should tell:
Quote
cat: one two three: No such file or directory
cat: four five six: No such file or directory
cat: seven: No such file or directory


Ok. I'm just about to... "Lose it. It means go crazy. Nuts. Insane. Bonzo. No longer in possession of one's faculties. Three fries short of a Happy Meal. WACKO!!"


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Feb. 01 2007,06:34 QUOTE

Well... you'd have to use something like a for loop to do that...
IFS=`printf "\n"`; for each_line in `cat list.txt`; do; cat "$each_line"; done
IFS is a special variable in posix shells that indicate the field separator (or something along those lines - usually set to whitespace)

Either way, you'll have a couple solutions... just choose one :P
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Feb. 03 2007,20:41 QUOTE

It's probably not worth trying to get things on one line. Using command substitution (backticks) will fail once you get to a certain size and needs to be avoided if you want to process a lot of files.

This is what I'd probably do:

Code Sample
# 1st make sure file ends in a newline
sed -i '$ s/$/\n/' list.txt;

while read LINE; do
     # set single quotes around each filename to be safe
    LN=\'"${LINE}"\'
    echo "${LN}" | xargs cat
done <"list.txt"


This has the advantage that your list of filenames list.txt can be arbitrarily long.

Not tried with busybox.
Back to top
Profile PM 
18 replies since Jan. 30 2007,09:45 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (4) </ 1 2 [3] 4 >/
reply to topic new topic new poll
Quick Reply: Little help needed

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code