The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delimited File Help garpal UNIX for Dummies Questions & Answers 6 03-28-2008 09:58 AM
awk - delimited output videsh77 UNIX for Advanced & Expert Users 1 12-04-2007 10:41 PM
Check whether a given file is in ASCII format and data is tab-delimited Mandab Shell Programming and Scripting 9 05-03-2007 07:25 PM
Delimited files hrshah74 Shell Programming and Scripting 4 02-01-2006 12:42 PM
Converting Tab delimited file to Comma delimited file in Unix charan81 Shell Programming and Scripting 22 01-20-2006 09:24 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 10-17-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
Thumbs up Looping thru tab delimited data

Hello people,
Can you please tell me how to loop thru the contents of a variable having tab delimited data using for loop in KSH.

For example:
data1 data2 data3 data4

How can I access the above data in a for loop? Please let me know. Thanks.

Regards,
T.
  #2 (permalink)  
Old 10-17-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
Got the solution. A simple for loop worked. thanks.

Regards,
T.
  #3 (permalink)  
Old 10-17-2006
gmgauthi gmgauthi is offline
Registered User
  
 

Join Date: Oct 2006
Location: Northern Illinois
Posts: 2
Willing to share it?
  #4 (permalink)  
Old 10-17-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
Here it is:

files=`ls -1 $dir`

for file in `echo $files`
do
echo $dir/$file
done

-- I wanted to list the files in a folder and use that list for further processing. Instead of taking the filenames into a file, I take it into a variable. The filenames here are tab delimited.

Regards,
T.
  #5 (permalink)  
Old 10-17-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
You certainly don't need to create "ls" and "echo" processes since KSH enables you to get your file list right from the for loop.

Code:
for file in $dir/*
do
     echo $file
done

This produces the same output with simpler logic.
  #6 (permalink)  
Old 10-17-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
The reason I was doing it that was for my code I need the filenames in bare format i.e just the file name without path.
Maybe I will use the basename function to extract just the filename.

Thanks tmarikle.
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 12:12 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