LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 11-28-2009, 07:28 PM   #1
astroumut
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Rep: Reputation: 0
Print full path+working folder by awk


Hi,

I would like to print pwd and working folder in one line by awk command in order to such a thing.

I have lots of folders and within each folder I have .sh files. I would like to create a script in the top folder which automates to run each process.


I create the folder list with this

Code:
ls -d */ > temp1
and the output will be like that;

temp1
Code:
myfolder1
myfolder2
myfolder3
...
and I am trying to create a file something like that by using pwd.

runscript
Code:
cd /Users/users/umut/stars1/myfolder1; ./mystars.sh
cd /Users/users/umut/stars1/myfolder2; ./mystars.sh
cd /Users/users/umut/stars1/myfolder3; ./mystars.sh
...



I used something like that but it does not work;
Code:
echo $PWD | awk '{print "cd ",$PWD,$1}' temp1 > runscript
The top folder also changes evertime, therefore I really have use pwd in order to learn in which folder I am in.

Thanks

Umut
 
Old 11-28-2009, 08:31 PM   #2
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
you can take advantage of the find command's -exec flag. When the argument to exec is invoked, the command runs in the directory containing the match.

find . -name mystars.sh -exec sh {} \;




Quote:
Originally Posted by astroumut View Post
Hi,

I would like to print pwd and working folder in one line by awk command in order to such a thing.


Umut
 
Old 11-28-2009, 11:44 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
if you have GNU find, you can use -printf with the various options such as %f, %p, %h etc. check the man page.
 
Old 11-29-2009, 02:55 AM   #4
astroumut
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks GooseYard,

I actually simplified my question by saying after I ''cd'' to the folder, I wanted to run ''./mystars.sh''. But in reality, I am going to run a different script which does not allow me to use -exec command. It is a quite nice approach, but it does not serve me how I want. It looks like I need a code to write the full path, enter the folder and do the job in there.

I will be glad if there are more suggestions.

Thanks
 
Old 11-30-2009, 08:27 AM   #5
astroumut
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Hi,

I have just found how to do it.

Code:
awk -v pwd="$PWD" '{print pwd"/"$0}'  temp1 > runscript
Thanks anyway for the help.

Umut
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How do I - not print - in awk? ZimMonkey Programming 10 08-21-2009 07:11 PM
How do I print the filename in awk? Disillusionist Programming 2 12-02-2008 12:20 PM
Shell: tr can only be used when given full path (despite being in $PATH) chochem Programming 2 06-27-2008 08:37 AM
How to parameterize which field awk should print? dbland07666 Linux - Newbie 2 10-29-2007 03:49 PM
How to see the full path of the computer I'm working on DNRN Linux - General 5 10-06-2006 06:05 AM

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

All times are GMT -5. The time now is 11:52 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration