2
votes
3answers
150 views

sed + remove the first directory from path

Please advise on how to remove the first directory from a path by sed, (the inverse pf what basename does). For example echo "/mnt/VPfig/Amer/AR4/Celtel/files/COM.txt" | sed ... I should get: ...
1
vote
1answer
42 views

Create a log file with the same name as input file

I'm new to linux shell scripting. I have few input files that I have to parse one by one. So in my "work in progress" WIP folder I have one input file at a time. While one file is under processing I ...
1
vote
2answers
45 views

Problems with basename in a loop

I am new at shell script programming and I'm trying to execute a software that reads a text and perform it's POS tagging. It requires an input and an output, as can be seen in the execute example: $ ...
11
votes
7answers
640 views

Shortest way to extract last 3 characters of base (minus suffix) filename

I'm trying to set a variable in an sh script to the last 3 characters of the base name of a file (by base name I mean without the path and without the suffix). I've succeeded in doing this but, purely ...
0
votes
5answers
108 views

how to extract part of a filename before '.' or before extension

I have files in format below: abc_asdfjhdsf_dfksfj_12345678.csv hjjhk_hkjh_asd_asd_sd_98765498.csv hgh_nn_25342134.exe I want to get the value before the . and after the last _. The result would ...
1
vote
2answers
2k views

How do I get absolute path from using find unix command

How to get absolute path by using find command. actually I am running the following script:- find . -size +20M | while read a do i=$(echo $a | sed 's:/: :g') echo $a; j=($i) ...
2
votes
2answers
107 views

Shell Scripting: how to use part of the file path as the file name?

I have a group of directories, each containing exactly 1 jpeg image, like so- /psds/folder1/image.jpg /psds/someotherfolder/picture.jpg /psds/yetanotherfolder/thumbnail.jpg What is the appropriate ...
2
votes
1answer
369 views

Find out if files in a folder exist under other name in other folder

Possibly a little incorrect English ahead: There are at least 2 folders. For this, A contains files without extension, usually usernames, and B contains similar files, with '.yml' extension or ...
2
votes
2answers
315 views

How do I check that a filename conforms to a pattern?

I'm tasked with writing a shell script which checks that a filename conforms to a specific pattern and I'm not sure how to go about it. The filename should follow a pattern which looks like: ...
8
votes
3answers
123 views

POSIX compliant way to work with a list of filenames possibly with whitespace

I have seen Bash scripting guides suggesting the use of array for working with filenames containing whitespace. DashAsBinSh however suggests that arrays are not portable so I am looking for a POSIX ...
0
votes
0answers
97 views

Shell Script : Check for all the source files in different paths

This is the naming convention of the file. <yearmonthdate>_<sourcesystem>_<totalnoofpartsof file>_<subject area>_<part number>.dat (or .dat.gz) First part is Date, ...
5
votes
1answer
246 views

Variable in sed

I have a file that contains filenames with absolute path. In the middle of that path, is a variable directory, whenever I hard code the variable part, it works fine, but when I replace it with the ...
3
votes
4answers
400 views

How to prepare files for rsync on a case insensitive filesystem?

I am transferring a large number of files on a HFS+ filesystem. The files are currently on ext2 partitions. I have conflicts due to case insensitivity of the target partition (HFS+). I want to ...
0
votes
2answers
229 views

Making md5sum understand file names with spaces

I need to use md5sum in Python by using pipe to calculate checksum for a bunch of .mp3 files... is there a command which ignore whitespaces in filenames on the command line of md5sum program? For ...
2
votes
1answer
191 views

Merging folders with practically the same name but different casing

When digging around in the advanced settings in Dropbox I lost a folder. I only discovered this about a month later. I managed to get this folder back from Dropbox however the file structure of the ...
1
vote
3answers
140 views

splitting the string in bash script

I am new to bash script. I am taking some input from user and checking details about that. Example: $HOME/Documents/test/one.txt I take the above string as an input and want to retrieve one.txt, I ...
0
votes
1answer
2k views

Why does scp say “No such file”?

I have a bash script that uses scp to copy a file from my machine to another. The script keeps on exiting after I enter the SSH password with the error: <filename>: No such file or directory ...
3
votes
3answers
321 views

Command for taking a screenshot to a new file

I want to configure a global hotkey to take a new screenshot and save it, say, somewhere inside my home folder. I can take a screenshot with ImageMagick with this command: import screenshot.jpg ...
0
votes
1answer
59 views

Get the most recent backup files [duplicate]

I'm googling for this, but the terms are so generic I'm getting way too many false positives, so what the hey, I'll ask here. I'm sure there's a simple answer but I don't generally script in *nix. ...
2
votes
2answers
1k views

How to find files by the time in their filename? [duplicate]

We have a directory contains files which contains time in their filename ./test.2013-06-11_06-01.gz ./test.2013-06-12_01-01.gz ./test.2013-06-13_03-01.gz ./test.2013-06-14_03-01.gz ...
8
votes
5answers
979 views

Portable way to get script's absolute path?

What is a portable way for a (zsh) script to determine its absolute path? On Linux I use something like mypath=$(readlink -f $0) ...but this is not portable. (E.g., readlink on darwin does not ...
-4
votes
1answer
64 views

How to copy datasets from prior version directory to latest version directory [closed]

I've go a number of directories named like: /data/db/OX/8_10 /data/db/OX/9_1 /data/db/OX/9_2 And need to copy some files (all the pt.* files) from the second latest one (above 9_1) to the latest ...
1
vote
3answers
391 views

Reading a directory in shell script

I want to read a numbered directory which is under a path, into a variable in shell script. The paths are something like this: .../releases/R1/... .../releases/R2/... .../releases/R3/... Each time ...
1
vote
2answers
172 views

How to “grab” matching files from a lookup file in bash?

I have a lookup file containing filenames. I also have a directory containing files, some of which have the names that correspond to some of the names in the directory. How can I: Move exact ...
0
votes
2answers
152 views

file command + how to view all results from file command

I use the file command in order to verify if file (PATH) is text/ascii file or encrypted file Because file command have allot of results ( small example in example 1 ) I want to get the all ...
0
votes
3answers
2k views

How to match a file name suffix

How to verify if the name of a .xml file name ended with .any-string? e.g. .previous or .backup or bck12 etc ... I need to print the XML file name except for XML files that end with ...
2
votes
1answer
511 views

Predict filename before downloading from a URL, in shell script

I have a shell script that downloads files from a list using wget, and resumes automatically if there is any non-critical error (because of unstable WIFI during storms). The problem is, I want to ...
0
votes
1answer
257 views

Checking existence of file with underscore in file name in zsh

I am writing a very simple script which will link shared configuration files. For some reason it does not behave as i expected for file with underscore in name. Does _ (underscore) means something ...
5
votes
1answer
2k views

Cannot open: Input/output error with tar command in a shell script

I am trying to create a tar ball in a shell script (I have enabled set -x), but I get an error: + cd /home5/mysite/public_html + TAR_DUMP=gypo_2012-02-18-03:51:15.tar.gz + echo 'Tar name: ...
1
vote
3answers
2k views

Script to show number of files (by file type) in a directory?

I want to show this kind of statistics about a particular directory: $ myscript.sh .c 34265 files .h 17866 files .cbl 1804 files .pco 389 files [...] Is there a tool that can do this? Here is my ...
9
votes
3answers
14k views

File extensions for unix shell scripts

On wikipedia, the article for .sh says: For the .sh file extension type, see Bourne shell. How about other unix shells? I know that the shebang is used inside the file to indicate an ...
14
votes
3answers
771 views

Newlines in filenames

I understand and accept the premise that defensive1 shell scripting is both prudent and, in the longer term, more sustainable. Many of the answers to text processing questions here follow this ...
2
votes
2answers
9k views

Bash shell script to locate and remove substring within a filename

I am trying to write a bash shell script in Mac OS X 10.6 (which is called by an Automator Action) to rename TV show DVD rips that I have named badly over the years. I want to remove part of the text ...
4
votes
1answer
3k views

Recursively compare directory contents by name, ignoring file extensions

I have a directory containing about 7,000 music files. I used lame to recursively re-encode all files in it to a separate directory, outputting all files with the same relative path and file name. ...