Sponsored Content
Top Forums Shell Programming and Scripting Bash looking in different directory for file that isn't referenced in command Post 302991157 by cmccabe on Tuesday 7th of February 2017 08:47:28 AM
Old 02-07-2017
Bash looking in different directory for file that isn't referenced in command

When I run the below bash I get the expected output, which is the sum of all matching targets less than 20 in $file1. The filename in the directory is fixed (in bold).

Code:
for file1 in /home/cmccabe/Desktop/test/panel/reads/16-0000_EPIL70.txt ; do
        bname=`basename $file1`
        pref=${bname%%_*.txt}
     awk '{gsub(/[()]/,_)} \
count[$5]==""{ count[$5]=0 } 
            $7 < 20{ count[$5]++} 
END{
              for(k in count) 
                 printf "%s %d\n",  k, count[k]
}' $file1 > /home/cmccabe/Desktop/test/panel/20x/base/16-0000_allepil70.bed
done

The desired bash is the exact same except the unique numerical digits, 16-0000 are read into a variable {pref}. This is because there can be multiple files with the same extension, but the digits are always unique.

Code:
for file1 in /home/cmccabe/Desktop/test/panel/reads/${pref}_EPIL70.txt ; do
        bname=`basename $file1`
        pref=${bname%%_*.txt}
     awk '{gsub(/[()]/,_)} \
count[$5]==""{ count[$5]=0 } 
            $7 < 20{ count[$5]++} 
END{
              for(k in count) 
                 printf "%s %d\n",  k, count[k]
}' $file1 > /home/cmccabe/Desktop/test/panel/20x/base/${pref}_allepil70.bed
done

awk: fatal: cannot open file `/home/cmccabe/Desktop/test/panel/reads/16-0000_epil70lessthan20xregions.txt_EPIL70.txt' for reading

The file that it is looking for is not in that directory, but not sure why it is even looking for it as I do not reference it at all in the command or do I? Thank you Smilie.

Code:
ls -l /home/cmccabe/Desktop/test/panel/reads
total 10952
-rw-rw-r-- 1 cmccabe cmccabe 11214550 Feb  7 07:27 16-0000_EPIL70.txt


Last edited by cmccabe; 02-07-2017 at 11:49 AM.. Reason: fixed format,
 

10 More Discussions You Might Find Interesting

1. Solaris

bash: ./<scriptname>: No such file or directory

I have simply downloaded a file to my local folder, made one small change and uploaded it back, ever since it will not run the file. I have now uploaded the original, unchanged file, which still doesn;t work. Evertime it is run ot says bash: ./nrcardprint: No such file or directory The... (10 Replies)
Discussion started by: Heidi.Ebbs
10 Replies

2. UNIX for Dummies Questions & Answers

deleting file that isn't really there

sorry about the title - I have a directory where a file is showing with ls or ls -l but if I try to reference it - I get the message that it isn't there. It is as if the directory structure isn't matching the actual content. Right now, I have two files of same name showing in the... (4 Replies)
Discussion started by: LisaS
4 Replies

3. Programming

Error: Undefined Symbol ..... First referenced in file......

Hi, I am working with Solaris 5.9 and I am newbie in Socket programming and I stated working with socket programming and I copyed a simple client & server program from a website which I am attaching with this and when I am compiling these files.I am getting the error-- Please Help me to... (1 Reply)
Discussion started by: smartgupta
1 Replies

4. Shell Programming and Scripting

[bash] reassigning referenced variables in functions

Hello all, Problem. ---------- I'm trying to reassign a referenced variable passed to a 'local' variable in a function but the local variable refuses to be assigned the content of the referenced variable. Any ideas would be appreciated. Objective. ----------- Eliminate all $VAR... (1 Reply)
Discussion started by: ASGR
1 Replies

5. Linux

bash:umount/: no such file or directory

I am trying to connect two system (let's say for time being) together such that it supports clustering. for this I got the following packages: # sudo apt-get install pacemaker sysv-rc-conf glusterfs-server glusterfs-examples glusterfs-client chkconfig nmap ntp Next, I did... (0 Replies)
Discussion started by: dr_mabuse
0 Replies

6. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

7. Shell Programming and Scripting

Bash to delete file in directory

Will the below bash delete all the "snps.ivg" in the given directory? Thank you :) find N:\all_array\Samples -maxdepth 1 -type f -name "snps.ivg" -delete (6 Replies)
Discussion started by: cmccabe
6 Replies

8. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

9. UNIX for Beginners Questions & Answers

Sourcing file from parent directory bash

"Debian 9 64x - LXDE" I try to source a file from my parent directory: #!/bin/bash #source.bash . ../links.bash but i get "file not found". I tried . "../links.bash" and . '../links.bash'. I got on all methods the same result. If i use the absolute path it works, but i don't want to... (4 Replies)
Discussion started by: int3g3r
4 Replies

10. UNIX for Beginners Questions & Answers

Unsure why access time on a directory change isn't changing

Hello... And thanks in advance for any help anyone can offer me I was trying to work out the differences between displaying modify, access, and change times with the 'ls' command. Everything seems in order when I look at files, but the access time on a directory doesn't seem to change when I... (4 Replies)
Discussion started by: bodisha
4 Replies
LIBBASH(7)							  libbash Manual							LIBBASH(7)

NAME
libbash -- A bash shared libraries package. DESCRIPTION
libbash is a package that enables bash dynamic-like shared libraries. Actually its a tool for managing bash scripts whose functions you may want to load and use in scripts of your own. It contains a 'dynamic loader' for the shared libraries ( ldbash(1)), a configuration tool (ldbashconfig(8)), and some libraries. Using ldbash(1) you are able to load loadable bash libraries, such as getopts(1) and hashstash(1). A bash shared library that can be loaded using ldbash(1) must answer 4 requirments: 1. It must be installed in $LIBBASH_PREFIX/lib/bash (default is /usr/lib/bash). 2. It must contain a line that begins with '#EXPORT='. That line will contain (after the '=') a list of functions that the library exports. I.e. all the function that will be usable after loading that library will be listed in that line. 3. It must contain a line that begins with '#REQUIRE='. That line will contain (after the '=') a list of bash libraries that are required for our library. I.e. every bash library that is in use in our bash library must be listed there. 4. The library must be listed (For more information, see ldbashconfig(8)). Basic guidelines for writing library of your own: 1. Be aware, that your library will be actually sourced. So, basically, it should contain (i.e define) only functions. 2. Try to declare all variables intended for internal use as local. 3. Global variables and functions that are intended for internal use (i.e are not defined in '#EXPORT=') should begin with: __<library_name>_ For example, internal function myfoosort of hashstash library should be named as __hashstash_myfoosort This helps to avoid conflicts in global name space when using libraries that come from different vendors. 4. See html manual for full version of this guide. AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <ril@ran4.net> SEE ALSO
ldbash(1), ldbashconfig(8), getopts(1), hashstash(1) colors(1) messages(1) urlcoding(1) locks(1) Linux Epoch Linux
All times are GMT -4. The time now is 05:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy