Sponsored Content
Top Forums Shell Programming and Scripting A simpler way to do this (save a list of files based on part of their name) Post 302843005 by LMHmedchem on Sunday 11th of August 2013 02:24:03 PM
Old 08-11-2013
Sorry for the delay, it has been an unexpectedly busy end of the week.

Quote:
Originally Posted by Don Cragun
The goal of The UNIX and Linux Forums is to help you learn how to do "stuff" on your own; not to write programs for you.
I completely understand and agree with this. I always try to start with a post that contains at least some kind of a working script. This is to do as much as I can on my own and let the other users here know that I am working to solve the problem, not expecting others to do it for me. I also think that compared to a text explanation, programming code is easier to read in terms of understand what a person is after. I read long prose explanations of code algorithms when I am having trouble falling asleep at night. I still haven't consistently found the sweet spot when it comes to exactly how much to post. It appears that my first attempt was to short to explain all I was trying to do, and my second was way too long to bother wading into.

It turns out that I didn't end up using an array. Everything that came out of the code you posted ended up in a single long string variable ($FILE_LIST). I just looped on the number of files I was expecting to find and parsed the long string to pull out the file name for each iteration of the loop.

Quote:
Originally Posted by Don Cragun
But, why have an array at all. Why not just process the files one at a time as they come out of awk?
The simple explanation for this is that I don't know awk very well at all. I can more or less use it to parse things, but only in the simplest implementations. I did spend some time trying to take the output from awk and work with it, but I think I was using a redirect instead of a pipe.

So as I read this now, ls is passing all .out.txt to sort, sort is sorting on the key field and passes the sorted list to awk. Awk processes each item in the list and outputs the specified fields. Then it looks like the output of awk is passed to read, which dumps the output into the vars $FILE_NAME and $RAND_SET. Once you are there, the rest is straightforward. I am not familiar with read, so that is something new to me. I would not have known how to get awk to output two variables and get them into something that I could use with cp. I am also not quite clear about how awk knows when it has read in enough lines to get to $FILE_COUNT. Is "NR" an implicit running counter of some kind so that when NR > $FILE_COUNT awk quits (I see that you have passed $FILE_COUNT to awk as c)?

From time to time I think I am getting better at this, then I try to do something new and find out how much I still don't know. I do really appreciate that help that is available here.

LMHmedchem
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

can I save list of files in memory and not in text file?

Hello all im using allot with the method of getting file list from misc place in unix and copy them into text file and then doing misc action on this list of files using foreach f (`cat file_list.txt`) do something with $f end can I replace this file_list.txt with some place in memory? ... (1 Reply)
Discussion started by: umen
1 Replies

2. UNIX for Dummies Questions & Answers

Report of duplicate files based on part of the filename

I have the files logged in the file system with names in the format of : filename_ordernumber_date_time eg: file_1_12012007_1101.txt file_2_12022007_1101.txt file_1_12032007_1101.txt I need to find out all the files that are logged multiple times with same order number. In the above eg, I... (1 Reply)
Discussion started by: sudheshnaiyer
1 Replies

3. Shell Programming and Scripting

strike last part from list of files

Hi, I have list of files as following: /home/abc/x/23344.php /home/axx/zz/ddddd/abc/7asda/2434.php /home/zzz/7x/y/114.php /home/assssc/x/yasyday/23664.php ( last part in each line is <somenumber.php> I need to somehow get this from the above: /home/abc/x/... (6 Replies)
Discussion started by: fed.linuxgossip
6 Replies

4. Shell Programming and Scripting

Compare two files based on integer part only

Please see how can I do this: File A (three columns): X1,Y1,1.01 X2,Y2,2.02 X3,Y3,4.03 File B (three columns): X1,Y1,1 X2,Y2,2 X3,Y3,4.0005 Now I have to compare file A and B based on the integer part of column 3. Means first 2 rows should be OK and the third row should not satisfy... (12 Replies)
Discussion started by: yale_work
12 Replies

5. Shell Programming and Scripting

find the line starting with a pattern and save a part in variable

Hi i have a file which has mutiple line in it. inside that i have a pattern similar to this /abc/def/hij i want to fine the pattern starting with "/" and get the first word in between the the symbols "/" i.e. "abc" in this case into a variable. thanks in advance (13 Replies)
Discussion started by: kichu
13 Replies

6. UNIX for Dummies Questions & Answers

List only files based on a pattern

Hi Gurus, I need to list only the files with out certain extension. For eg from the following list of files: I need to only list: Thanks Shash (7 Replies)
Discussion started by: shash
7 Replies

7. Shell Programming and Scripting

List duplicate files based on Name and size

Hello, I have a huge directory (with millions of files) and need to find out duplicates based on BOTH file name and File size. I know fdupes but it calculates MD5 which is very time-consuming and especially it takes forever as I have millions of files. Can anyone please suggest a script or... (7 Replies)
Discussion started by: prvnrk
7 Replies

8. Shell Programming and Scripting

Save value from output of Corestat and save in a list for each core

I am trying to modify the "corestat v1.1" code which is in Perl.The typical output of this code is below: Core Utilization CoreId %Usr %Sys %Total ------ ----- ----- ------ 5 4.91 0.01 4.92 6 0.06 ... (0 Replies)
Discussion started by: Zam_1234
0 Replies

9. UNIX for Dummies Questions & Answers

Rename files based on a list

Hi, I have a directory with a lot of files like this: a.bam b.bam c.bam I like to rename these files based on a list where the name of the files in the first column will be replasced by the names in the second column. Here is my list which is a tab-delimited text file: a x b y c ... (4 Replies)
Discussion started by: a_bahreini
4 Replies

10. Shell Programming and Scripting

Save an specific part of a expect_out in a variable

I have a expect file like this #!/opt/tools/unsupported/expect-5.39/bin/expect spawn ssh -l user ip expect_after eof {exit 0} set timeout 10 log_file /report.txt expect "Password:" { send "pasword\r" } expect "$ " { send "date\r" } expect "$ " { send "readlink /somelink\r" } set... (7 Replies)
Discussion started by: bebehnaz
7 Replies
IPESCRIPT(1)						      General Commands Manual						      IPESCRIPT(1)

NAME
ipescript - Run an Ipe script (written in Lua) SYNOPSIS
ipescript script { arguments } DESCRIPTION
ipescript runs an Ipe script written in Lua. The Ipe bindings are automatically available in the script. Ipescript looks for the script in any of the script directories. The script argument should not contain the .lua extension. ENVIRONMENT VARIABLES
ipescript respects the following environment variables: IPELATEXDIR the directory where ipetoipe runs Pdflatex. IPESCRIPTS a list of directories where Ipescript will look for scripts. When this variable is not set, Ipe searches first the current directory, then ~/.ipe/scripts, and finally the system-wide Ipe script directory. When this variable is set, it should contain a list of directories, separated by semicolons. A single under- score is replaced by the system-wide Ipe script directory. IPEDEBUG set this to 1 for debugging output from ipescript. AUTHOR
Otfried Cheong REPORTING BUGS
Please report bugs using Ipe bugzilla at http://ipe7.sourceforge.net/bugzilla.html SEE ALSO
Ipe is documented fully in The Ipe Manual, which is available online at http://ipe7.sourceforge.net/manual/manual.html . August 28, 2011 IPESCRIPT(1)
All times are GMT -4. The time now is 10:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy