LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   stupid question: awk and space prob (https://www.linuxquestions.org/questions/programming-9/stupid-question-awk-and-space-prob-588936/)

frenchn00b 10-02-2007 01:31 PM

stupid question: awk and space prob
 
Hi,
I am bumping on a stupid one :-)

I have in my folder
ZURICK .htm
ZURICK2 .htm
ZURICK3 .htm

Code:

ls *.htm | awk '  {  print $0 ;  file =" "$0" "; system( " cat " file ) }  '
and it says:
Code:

ZURICK .htm
cat: ZURICK: No such file or directory
cat: .htm: No such file or directory
ZURICK2 .htm
cat: ZURICK2: No such file or directory
cat: .htm: No such file or director
ZURICK3 .htm
cat: ZURICK3: No such file or directory
cat: .htm: No such file or director

I am bumping on such easy stuff :(

--
same for this with sh:
Quote:

File=`echo "$(ls *.htm)" `
echo $File
for each in $File ; do cat $File ; done
--
this not working either :
Quote:

File=`echo "$(ls *.htm)" `
echo $File
for each in "$File" ; do echo "$each" ; cat "$each" ; done



By the way, it is with cygwin

druuna 10-02-2007 01:58 PM

Hi,

Your missing, or misplacing, double quotes:

This: ls *.htm | awk ' { print $0 ; file =" "$0" "; system( " cat " file ) } '
Should be this: ls *.htm | awk ' { print $0 ; file =" \""$0"\" "; system( " cat " file ) } '

This puts literal double quotes around $0, making it part of file.

This: for each in "$File" ; do echo "$each" ; cat "$each" ; done
Should be: for each in $File; do echo $each; cat "$each" ;done

The double quotes around $File should not be there. Otherwise $File would have one entry only, namely the whole string that the ls command came up with.

BTW: Why use: File=`echo "$(ls *.htm)" ?
Wouldn't: File=*htm be easier or File="`ls *htm`" if you want more readability.

Hope this helps.

ilikejam 10-02-2007 02:00 PM

Hi.

Probably better with
Code:

for go in *.htm
  do
  echo "$go"
  cat "$go"
done

Dave

Edit. Gah! Beaten to it.

trashbird1240 10-02-2007 02:13 PM

What are you trying to do? Remove the spaces?

Joel

frenchn00b 10-02-2007 02:46 PM

Thanks a lot lot guys !!! that's so helpful

Now I get error msg when typign this:

Code:

ls *.htm  | awk ' {  file =" \""$0"\" "; system( "./getthefollowinglinkinto.sh "    file )  ; next } '

Code:

ls *.htm  | awk ' {  file =" \""$0"\" "; system( " sh getthefollowinglinkinto.sh "    file )  ; next } '
(after chmod +x getthefollowinglinkinto.sh that is in same folder)

Not easy ... but I am trying hard





----
better, when this:

Quote:

#!/bin/bash
for go in *.htm
do
echo "$go"
./getthelinkinto.sh "$go"
done
with the script having a "$1" inside ... pff pff

I get :
Quote:

No such file or directory

druuna 10-02-2007 03:00 PM

Hi,

What is it you are trying to do (in general)?

I'm asking because all that is done in getthelinkinto.sh can also be done inside the script that calls getthelinkinto.sh. Seems like a hard way to do things.

frenchn00b 10-02-2007 03:17 PM

Quote:

Originally Posted by druuna (Post 2910912)
Hi,

What is it you are trying to do (in general)?

I'm asking because all that is done in getthelinkinto.sh can also be done inside the script that calls getthelinkinto.sh. Seems like a hard way to do things.


In the getthelinkinto.sh, there is:
Code:

#!/bin/sh
echo "$1"


For the moment, just bit of training with spaces, ... since I made already a script but got it wrong with spaces problems. I removed all and started from begining to learn space stuffs.

THanks a lot for support. Btw, awk rocks really !!

Cool Link: http://www.grymoire.com/Unix/Awk.html

ghostdog74 10-02-2007 10:48 PM

Quote:

Originally Posted by frenchn00b (Post 2910798)
Code:

ls *.htm | awk '  {  print $0 ;  file =" "$0" "; system( " cat " file ) }  '

that's probably overkill. From what i see, you can just do a simple
Code:

cat *htm
heres a few ways in GNU awk
Code:

awk '1' *htm
Code:

awk 'BEGIN{n=FILENAME}
    n != FILENAME {n=FILENAME;
                  print "******************";
                  print n
    }
    1
' *htm


frenchn00b 10-16-2007 04:11 AM

same problem ... this is not working :(

Code:

#!/bin/bash
  auflist="$(find -iname '*.pdf')"
  for each in "$auflist"
  do
      echo "$each"
      cat  "$each"
  done


angrybanana 10-16-2007 11:39 AM

Fix it up how you like, this works.
Code:

find -name '*.pdf'|while read each;do cat "$each";done

ghostdog74 10-16-2007 06:23 PM

Quote:

Originally Posted by angrybanana (Post 2926302)
Fix it up how you like, this works.
Code:

find -name '*.pdf'|while read each;do cat "$each";done

there's no need to use a while loop to "cat" each file found, since "cat" itself loops over lines of files internally. Minimally,
Code:

find -name .... | xargs cat
or something like that.


All times are GMT -5. The time now is 05:32 AM.