UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 29th, 2011, 01:50 PM
jgrosecl jgrosecl is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 7 jgrosecl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 39 m 15 sec
Reputation Power: 0
Read and Replace

Read and Replace

--------------------------------------------------------------------------------

Hi!
I think my last post was a little confusing, so I will try an post a sample this time.
I have a script which is supposed to output two columns of a file to a different file, then take the first column, search a directory for it, and replace anything it finds with the second column. This is what I have:

for file in /XXXX/XXXX/XXXX/I
do
echo $VAR|awk '{printf "%d\n",$1}'|read NEWVAR
done
awk < XXXX_table.txt '{print $1 $3}' >> var1
for line in /XXXX/XXXX/XXXX/var1
do
x=$(awk < var1 '{print $1}')
y=$(awk < var1 '{print $2}')
cd /XXXX/XXXX/XXXX/I
sed "s/$x/$y/g"
echo $x
echo $y
done

The first loop is supposed to remove all of the leading zeroes in all the files in that directory as well, but I guess that is wrong too.

Having lots of difficulty on this one, but I feel as though the answer is very simple

Reply With Quote
  #2  
Old June 29th, 2011, 04:37 PM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,111 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 7 h 43 m 38 sec
Reputation Power: 1485
First problem - where does $VAR come from?
Why are you doing that first loop which will only (once it runs correctly) ever produce a result that you can use from the last iteration.

Let's go back to basics. You have a directory, containing files whose names follow a particular pattern. Show a couple of examples of the names. You mention the files have two columns which you wish to do some operations upon. Show a couple of examples of the content. Also, do the files contain just one line or many? If many do you want the operation to be performed on all or just some of those lines?

Don't use awk < a_file_name '{print $1}' - use: awk '{print $1}' a_file_name

You refer to file names ($VAR and XXXX_table.txt) without a path, then do a change directory (in a loop, which is a redundant thing to do!).
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Read and Replace

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap