LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 03-08-2009, 08:43 PM   #1
slcalice
LQ Newbie
 
Registered: Jun 2006
Posts: 5

Rep: Reputation: 0
Question how to read input line by line (awk)


Hi everybody,

I try to write a script which automotize some works.

On the remote desktop I have some directories like that;

Quote:
/Remotedesktop/raskapov/AAAAA
/Remotedesktop/raskapov/BBBBBB
/Remotedesktop/raskapov/CCCCC
/Remotedesktop/raskapov/DDDDD
/Remotedesktop/raskapov/EEEEEE

(there are some files in these directories.
For example:
/Remotedesktop/raskapov/AAAAA/bbb.py
/Remotedesktop/raskapov/AAAAA/ccc.py)

I would like to pick up these files to my local area.

So I write directory names to a txt file:

Quote:
data.txt

AAAAA
BBBBBB
CCCCC
DDDDD
EEEEEE

Code:
#!/bin/ksh
file='data.txt'
  l=1
  while read line
   do
  echo $line
    rfdir /Remotedesktop/raskapov/${line} > bufferx.txt
     awk '{sub(/^/, "/Remotedesktop/raskapov/");print}' bufferx.txt > ${line}.txt
  ((l+=1))
done < "${file}"
This gives output:

AAAAA.txt
BBBBBB.txt
...
EEEEEE.txt


When you look at one of these files for example AAAAA.txt;

I see the path of the files like that;

/Remotedesktop/raskapov/bbb.py
/Remotedesktop/raskapov/ccc.py


But they must be

/Remotedesktop/raskapov/AAAAA/bbb.py
/Remotedesktop/raskapov/AAAAA/ccc.py


like these. How could I fix the correct path of the files ?

I have to write something different than this line:

awk '{sub(/^/, "/Remotedesktop/raskapov/");print}' bufferx.txt > ${line}.txt
 
Old 03-09-2009, 08:50 AM   #2
emi_ramo
Member
 
Registered: Apr 2007
Location: Barcelona, Spain
Distribution: Debian, KUbuntu
Posts: 213

Rep: Reputation: 36
Try with this:

Code:
#!/bin/ksh
file="data.txt"
remotedir="/Remotedesktop/raskapov/"

cat $file | while read line ; do
   # This line for debugging
   echo $line
   rfdir ${remotedir}${line} | while read remoteline ; do
      # This line for debugging
      echo ${remoteline}
      echo ${remotedir}${line}${remoteline} > ${line}.txt
   done
done
I don't know ksh so much. I instead usually use bash. If this script doesn't run ok with ksh it will do with bash, sure.
 
Old 03-09-2009, 09:38 AM   #3
slcalice
LQ Newbie
 
Registered: Jun 2006
Posts: 5

Original Poster
Rep: Reputation: 0
It works both sh and ksh. But if I use this script, some format problem I will have.

I solved the problem by writing this line;

awk -v line=$line '{sub(/^/, "/You can paste like this/"line"/");print}' data2.txt > ${line}.txt

Thanks
 
Old 03-09-2009, 09:41 AM   #4
emi_ramo
Member
 
Registered: Apr 2007
Location: Barcelona, Spain
Distribution: Debian, KUbuntu
Posts: 213

Rep: Reputation: 36
What does 'some format problem' means?
 
Old 03-09-2009, 03:12 PM   #5
sureshsujatha
Member
 
Registered: Mar 2009
Posts: 40

Rep: Reputation: 15
@emi_ramo,
Really neat script ... Respect !!!

Last edited by sureshsujatha; 03-14-2009 at 01:20 AM.
 
  


Reply

Tags
awk


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
grab the line below a blank line and the line above the next blank line awk or perl? Pantomime Linux - General 7 06-26-2008 09:13 AM
[SOLVED] use awk &/or sed to read file 1 line 1 & file 2 line 1 gr8scot Linux - General 6 07-12-2007 09:13 PM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 02:43 PM
read the input file from the specified line no till end suchi_s Programming 5 09-09-2004 05:36 AM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 11:24 PM


All times are GMT -5. The time now is 04:45 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration