The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to make a function friend to both base and derived class ennstate High Level Programming 3 05-29-2008 08:11 PM
How to make a loop base on reading a file? JohnBalayo HP-UX 3 04-02-2008 12:58 AM
How to build as web base File Server satimis Ubuntu 1 01-05-2008 08:56 AM
Reading 5 Students names and grades using while loop???? dlbomber1 Shell Programming and Scripting 1 11-26-2007 02:46 AM
Using loop reading a file,retrieving data from data base. Sonu4lov Shell Programming and Scripting 1 01-19-2007 03:38 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-01-2008
JohnBalayo JohnBalayo is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 4
How to make a loop base on reading a file?

To make it clearer:

I have a file, List.txt
List.txt contains: (these are actually splitted files w/c I got from ls command and dump them to the List.txt file)

SAMPLEa
SAMPLEb
SAMPLEc
SAMPLEd
SAMPLEe
SAMPLEf
.
.
.
.
.

And I want to rename these files to have a .dat extension. (ie. SAMPLEa.dat, etc…)
Please see code snippet below. It’s not working and your valuable suggestion will be highly appreciated.

#!/bin/csh
# Looping

cat list.txt | while read line
do
mv $line $line.dat
done


Thanks in advance for the help…

Last edited by JohnBalayo; 04-02-2008 at 03:14 AM.. Reason: To make the question clearer.
  #2 (permalink)  
Old 04-02-2008
lowbyte lowbyte is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 73
Hey,

better do the following:

for i in `cat <your textfile>`
do
mv $i $i.dat
done


CU
lowbyte
  #3 (permalink)  
Old 04-02-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,585
Greetings,

Nothing wrong with the code except for one (big) point :
In its current form, its incompatible (while expression syntax) with the shell (csh) you wish to use...
Up to you: or you correct it, or you use (what most of us do, for compatibility...) sh or ksh
comment your first line and you will see it work!

All the best
  #4 (permalink)  
Old 04-02-2008
JohnBalayo JohnBalayo is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 4
Thanks a lot guys for the help... Got the script now working.... :-)
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0