LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 10-02-2007, 01:31 PM   #1
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
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

Last edited by frenchn00b; 10-02-2007 at 01:40 PM.
 
Old 10-02-2007, 01:58 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 10-02-2007, 02:00 PM   #3
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

Probably better with
Code:
for go in *.htm
  do
  echo "$go"
  cat "$go"
done
Dave

Edit. Gah! Beaten to it.

Last edited by ilikejam; 10-02-2007 at 02:02 PM.
 
Old 10-02-2007, 02:13 PM   #4
trashbird1240
Member
 
Registered: Sep 2006
Location: Durham, NC
Distribution: Slackware, Ubuntu (yes, both)
Posts: 463

Rep: Reputation: 31
What are you trying to do? Remove the spaces?

Joel
 
Old 10-02-2007, 02:46 PM   #5
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Original Poster
Rep: Reputation: 57
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

Last edited by frenchn00b; 10-02-2007 at 02:50 PM.
 
Old 10-02-2007, 03:00 PM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 10-02-2007, 03:17 PM   #7
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Original Poster
Rep: Reputation: 57
Quote:
Originally Posted by druuna View Post
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

Last edited by frenchn00b; 10-02-2007 at 03:18 PM.
 
Old 10-02-2007, 10:48 PM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by frenchn00b View Post
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

Last edited by ghostdog74; 10-02-2007 at 10:51 PM.
 
Old 10-16-2007, 04:11 AM   #9
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Original Poster
Rep: Reputation: 57
same problem ... this is not working

Code:
#!/bin/bash
  auflist="$(find -iname '*.pdf')"
  for each in "$auflist"
   do
      echo "$each"
      cat  "$each"
   done
 
Old 10-16-2007, 11:39 AM   #10
angrybanana
Member
 
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
Fix it up how you like, this works.
Code:
find -name '*.pdf'|while read each;do cat "$each";done

Last edited by angrybanana; 10-16-2007 at 11:45 AM.
 
Old 10-16-2007, 06:23 PM   #11
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by angrybanana View Post
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.

Last edited by ghostdog74; 10-16-2007 at 06:27 PM.
 
  


Reply



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
awk - working with space and tab indiancosmonaut Programming 7 07-10-2007 12:46 PM
Stupid, stupid question; I lost Klaptop. :( Surfrider Slackware 2 08-31-2005 09:12 PM
Stupid Dumb Stupid Question... drigz Linux - Software 3 09-23-2004 03:09 PM
prob a stupid question on glibc Notyou Linux - Newbie 3 08-17-2004 03:52 PM
this prob sounds stupid but... villieb Linux - Newbie 4 04-17-2004 04:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:42 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
Open Source Consulting | Domain Registration