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
SYSPROFILE(8)						      System Manager's Manual						     SYSPROFILE(8)

NAME
sysprofile - modular centralized shell configuration DESCRIPTION
sysprofile is a generic approach to configure shell settings in a modular and centralized way mostly aimed at avoiding work for lazy sysad- mins. It has only been tested to work with the bash shell. It basically consists of the small /etc/sysprofile shell script which invokes other small shell scripts having a .bash suffix which are contained in the /etc/sysprofile.d/ directory. The system administrator can drop in any script he wants without any naming convention other than that the scripts need to have a .bash suffix to enable automagic sourcing by /etc/sysprofile. This mechanism is set up by inserting a small shell routine into /etc/profile for login shells and optionally into /etc/bashrc and/or /etc/bash.bashrc for non-login shells from where the actual /etc/sysprofile script is invoked: if [ -f /etc/sysprofile ]; then . /etc/sysprofile fi For using "sysprofile" under X11, one can source it in a similar way from /etc/X11/Xsession or your X display manager's Xsession file to provide the same shell environment as under the console in X11. See the example files in /usr/share/doc/sysprofile/ for illustration. For usage of terminal emulators with a non-login bash shell under X11, take care to enable sysprofile via /etc/bash.bashrc. If not set this way, your terminal emulators won't come up with the environment defined by the scripts in /etc/sysprofile.d/. Users not wanting /etc/sysprofile to be sourced for their environment can easily disable it's automatic mechanism. It can be disabled by simply creating an empty file called $HOME/.nosysprofile in the user's home directory using e.g. the touch(1) command. Any single configuration file in /etc/sysprofile.d/ can be overridden by any user by creating a private $HOME/.sysprofile.d/ directory which may contain a user's own version of any configuration file to be sourced instead of the system default. It's names have just to match exactly the system's default /etc/sysprofile.d/ configuration files. Empty versions of these files contained in the $HOME/.syspro- file.d/ directory automatically disable sourcing of the system wide version. Naturally, users can add and include their own private script inventions to be automagically executed by /etc/sysprofile at login time. OPTIONS
There are no options other than those dictated by shell conventions. Anything is defined within the configuration scripts themselves. SEE ALSO
The README files and configuration examples contained in /etc/sysprofile.d/ and the manual pages bash(1), xdm(1x), xdm.options(5), and wdm(1x). Recommended further reading is everything related with shell programming. If you need a similar mechanism for executing code at logout time check out the related package syslogout(8) which is a very close compan- ion to sysprofile. BUGS
sysprofile in its current form is mainly restricted to bash(1) syntax. In fact it is actually a rather embarrassing quick and dirty hack than anything else - but it works. It serves the practical need to enable a centralized bash configuration until something better becomes available. Your constructive criticism in making this into something better" is very welcome. Before i forget to mention it: we take patches... ;-) AUTHOR
sysprofile was developed by Paul Seelig <pseelig@debian.org> specifically for the Debian GNU/Linux system. Feel free to port it to and use it anywhere else under the conditions of either the GNU public license or the BSD license or both. Better yet, please help to make it into something more worthwhile than it currently is. SYSPROFILE(8)
All times are GMT -4. The time now is 02:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy