list file content as individual variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting list file content as individual variables
# 1  
Old 10-06-2009
list file content as individual variables

Hello,

I've created a couple of files within a list using the command "ls -ltr | tail -2 > list" These files are the newest files placed within a directory. From the "list" file, I need to place the filenames as a variable. In which the newest file will be called "new_ctrl" the older file called "old_ctrl".

Here is the "list" input file (after using awk to list the date & filename):
Sep 12 11:06 cms38_Sep12.log
Sep 29 11:29 cms38_09_25_09.log

What I need:
new_ctrl="cms38_09_25_09.log"
old_ctrl="cms38_09_25_09.log"

I'm using BSH.

Your help would be greatly appreciated here.

Thank you for your time.
Pete

---------- Post updated at 09:43 AM ---------- Previous update was at 09:42 AM ----------

Sorry - Mistake on ctrl file output:

new_ctrl="cms38_09_25_09.log"
old_ctrl="cms38_Sep12.log"
# 2  
Old 10-06-2009
Hi.

Code:
read old_ctrl new_ctrl <<< $(ls -tr | tail -2)

(for ksh...)
Code:
echo $(ls -tr | tail -2) | read old_ctrl new_ctrl


Last edited by Scott; 10-06-2009 at 12:31 PM..
# 3  
Old 10-06-2009
Thanks for your response. For the first code, there were no files that were created. Although there were no error messages. What am I missing?

Thanks Again!
# 4  
Old 10-06-2009
Hi.

Actually this was to bypass the need to create the file.

But if you still want to create it then:

Code:

ls -tr | tail -2 > list
read old_ctrl new_ctrl < $(cat list)

(perhaps there's a better way than using cat - I'm more of a ksh person!)
# 5  
Old 10-06-2009
Thanks!

I think I got it. I appreciate your input. You got me out of a jam!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List the files after sorting based on file content

Hi, I have two pipe separated files as below: head -3 file1.txt "HD"|"Nov 11 2016 4:08AM"|"0000000018" "DT"|"240350264"|"56432" "DT"|"240350264"|"56432" head -3 file2.txt "HD"|"Nov 15 2016 2:18AM"|"0000000019" "DT"|"240350264"|"56432" "DT"|"240350264"|"56432" I want to list the... (6 Replies)
Discussion started by: Prasannag87
6 Replies

2. UNIX for Dummies Questions & Answers

List all File Content its subdirectory

Is there anyway to display the file content in a subdirectory that starts or ends with a certain filename, say .txt? or start with NTS $ ls * dos2unix.bat dos2unix.exe test.txt FilePermissions: filepermission.html NTSLA32_SystemDrive.txt NTSLA36_regedit.txt filepermission.sh ... (1 Reply)
Discussion started by: alvinoo
1 Replies

3. Shell Programming and Scripting

list file content

I need help. I have this file, it has 2 fields with at least 300 lines: 1 4 2 3 3 6 4 2 . . 300 5 My output should be for every line in input file the output should be like this, for example line 1: wget http://somewebsite/page=1&line=1 wget http://somewebsite/page=1&line=2 wget... (4 Replies)
Discussion started by: zorrox
4 Replies

4. UNIX for Dummies Questions & Answers

Parse or cut concat variables to individual values

Hello I need to pass some environment parameters to a datastage job and am getting an error when trying to send the complete concatinated variable. I have decided to parse out just the values and send as parameters but am struggling to find the best way to do this (actually I am not very... (3 Replies)
Discussion started by: LynnC
3 Replies

5. Shell Programming and Scripting

Turning CSV files into individual Variables

I want to be able to convert the following data from a CSV into individual variables from the columns 2 4 and 8 I can use awk to grab the columns using var1=`cat text.csv | awk "," '{print $2}'` but how do I create separate variables for each line. 595358 ,ECON1010 ,THU ,08:00 - 10:00 ,11 Mar... (6 Replies)
Discussion started by: domsmith
6 Replies

6. UNIX for Dummies Questions & Answers

How to list content with file name ?

I want to search the string including the symbol like 'search' for example, file a.txt in \\dir contains, a for 'appable' b for 'banana' c for 'cat' s for 'search' Here I need to display(serach outpur) like \\dir\a.txt s for 'search' ... ... How to list content with file name... (5 Replies)
Discussion started by: gkskumar
5 Replies

7. Shell Programming and Scripting

Moving Content from one file to another with variables

Greetings All, Need some help, your input is appreciated. Scenario: I have five files, each has one line with comletely different content. I execute the command to combine all the five lines of content into a single file. Goal: I would like to take that single file that has the... (3 Replies)
Discussion started by: royarellano
3 Replies

8. Shell Programming and Scripting

Need help with awk - how to read a content of a file from every file from file list

Hi Experts. I need to list the file and the filename comes from the file ListOfFile.txt. Basicly I have a filename "ListOfFile.txt" and it contain Example of ListOfFile.txt /home/Dave/Program/Tran1.P /home/Dave/Program/Tran2.P /home/Dave/Program/Tran3.P /home/Dave/Program/Tran4.P... (7 Replies)
Discussion started by: tanit
7 Replies

9. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies

10. Shell Programming and Scripting

Put content of file into variables

How to put a line of strings (with some white spaces in between) from a file into variables? I have tried the following codes. However, the content is cut by space (not by line) for i in `cat ${source_file}` do echo $i done Please comment. Thanks. (2 Replies)
Discussion started by: Rock
2 Replies
Login or Register to Ask a Question