Parsing file list in variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing file list in variable
# 1  
Old 09-24-2010
Parsing file list in variable

Hello,
somewhere in a shell script, i am storing the output of "ls" into a variable. My question is how can i parse this variable to get each filepath. I don't want to create a temporary file to write down all the filenames and then parse it..

is there a easy way out..

here is what i am doing

Code:
tempVar=`find {some files according to pattern} | grep "some pattern"`

So tempVar has a list of filepaths, i would like to parse this. May be this is simple, but since i am not so well versed with shell scripting, please help me.

rgds
Prash
# 2  
Old 09-24-2010
Code:
for i in $tempVar 
do
  echo $i
done

This User Gave Thanks to anbu23 For This Post:
# 3  
Old 09-24-2010
in ksh:

Code:
for file in $tempVar ; do

  echo $file

done

... in csh:

Code:
set x='ant bat cat dog'

foreach y ( $x )

  echo $y

end

# 4  
Old 09-24-2010
thank you for the quick reply.. it works. I think this is a very basic question.. sorry Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Applying sed against a file from a list of values stored in a variable

Hi Forum. I have the following challenge at work that I need to write a script for. I have a file abc.txt with the following contents: 4560123456 4570987654 4580654321 I want to be able to search/replace in abc.txt - the first 4 characters anything starting with 4560 to 7777; 4570... (3 Replies)
Discussion started by: pchang
3 Replies

2. Shell Programming and Scripting

Parsing csv file and pass to a variable

Hi, Newbie here and I need some help to parse a csv file that contains fields separated by ",". What I need to achieve here is, read the 1 line file and extract 240 fields and pass to a variable and then read the next 240 fields and pass to a variable, over and over. If anyone can assist that... (4 Replies)
Discussion started by: tmslixx
4 Replies

3. UNIX for Dummies Questions & Answers

Parsing file, reading each line to variable, evaluating date/time stamp of each line

So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated. Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies

4. Shell Programming and Scripting

set a variable to be a list of file names

Hi all, I am trying to get a list of all the .tif images in my folder and set a variable that holds all the file names using C shell. What is the best way to do it? any help would be greatly appreciated. Yang (4 Replies)
Discussion started by: lionheartyoung
4 Replies

5. Shell Programming and Scripting

How to get a very big file sorted by contents of another variable list in one pass?

I have two list.... One has 17m (yes that's million) records in it which relate to the path and file name of individual text files. At the start of the pathname is a two character identifier identifying which category it belongs in as identified by a second file with the two character lookup... (10 Replies)
Discussion started by: Bashingaway
10 Replies

6. UNIX for Dummies Questions & Answers

Parsing a variable

Can someone help me? I have been looking in the archives as I am sure this is very simple to do, but I do not know. I have a variable which sometimes contains a file name and sometimes contains a fully qualified file name. I want to be able to separate the directory from the file name into 2... (3 Replies)
Discussion started by: CAGIRL
3 Replies

7. Shell Programming and Scripting

parsing data from xml file is failing can't open variable

Created a korn shell script, everything is is working except this section, the variable $SYSINFO is being set, but the NASIP & NASDEV are failing, it appears to be treating the config.xml file config directory and xml as the file. Need a second set of eyes to tell me where I am messing up. #... (3 Replies)
Discussion started by: juanb25
3 Replies

8. Shell Programming and Scripting

Parsing a variable length file

Hi I am new to shell scripting. I need to parse a file which contains the header and detail records and split into n of file based on dept ID, for ex. INPUT FILE: DEPT ID: 1 EMPNAME: XYZ EMPAddress: XYZZZ DEPT ID: 2 EMPNAME: ABC EMPAddress: ABCD DEPT ID: 1 EMPNAME: PQR EMPAddress:... (6 Replies)
Discussion started by: singhald
6 Replies

9. Shell Programming and Scripting

parsing a variable

Hi, I want to get an input from user and parse the input. The legal characters allowed in the input are alnum(a-zA-Z0-0), . , - Also the first and las characters must be alnum only. e.g if the input is abc.ghh-sok.com then the script should return correct, and if the input is like... (2 Replies)
Discussion started by: g_rohit7
2 Replies

10. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies
Login or Register to Ask a Question