Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

SHELL SCRIPTING

Name: Anonymous 2009-08-28 15:15

so i have a for loop in a bash script:

for var in file; do
   echo $var
   continue
done

the file contains plain text:
11111111
22222222
3333 3333
44444444

the output should exactly look like the input file, but the above for loop gives me that:
11111111
22222222
3333
3333
44444444

tl;dr:
so how do i make for ignore the space?

Name: Anonymous 2009-08-28 15:21

you don't

use perl maybe?

Name: Anonymous 2009-08-28 15:22

Please use the [code] tags for your code thank you.

Name: Anonymous 2009-08-28 15:23

google's that way -->

Name: Anonymous 2009-08-28 15:23

Name: Anonymous 2009-08-28 15:23

sed -e s/  *//g'


Or 's/ +//g' if you're a PERLIST.

Name: Anonymous 2009-08-28 15:26

>>6
Don't help him!

Name: Anonymous 2009-08-28 15:38

>>7
I'm not helping him; I'm helping myself. You will understand one day.

Name: Anonymous 2009-08-28 15:48

>>6
this will just cut out the space, and that doesn't help me since i need it

Name: Anonymous 2009-08-28 15:52

Maybe try:
for var in `cat file`; do

which should assign each complete line (with spaces) as a variable.

Name: Anonymous 2009-08-28 15:56

>>10
3/10

Name: Anonymous 2009-08-28 16:06

while read line
do  echo "$line"
done < file


Or the optimized form:
cat file

Name: Anonymous 2009-08-28 16:11

>>10
the spaces will still screw up your giant cock. Let's talk about escaping.
This work pretty well:


for i in $(cat test | sed -re 's/ /\x1b/g');
do
  echo $i | sed -re 's/\x1b/ /g';
done

Name: Anonymous 2009-08-28 16:33

OP here
/g/ was actually pretty helpfull, this here works for me:

cat file |
while read VAR; do
   echo $VAR
   continue
done

Name: Anonymous 2009-08-28 16:33

$ perl -pe '' <file
11111111
22222222
3333 3333
44444444
$

Name: Anonymous 2009-08-28 16:38

>>14
That's nice, seeing as /g/ is the place for such retarded, google-able questions. Come back when you've read SICP.

Name: Anonymous 2009-08-28 17:46

>>16
Oh, yes. In fact SICP helps with shell scripting.
back to /prog/, please.

Name: Anonymous 2009-08-28 17:47

>>17
...wait...

Name: Anonymous 2010-12-09 12:34

Name: Anonymous 2011-02-03 2:12

Don't change these.
Name: Email:
Entire Thread Thread List