Substitution in %x command in Ruby [closed] - ruby

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am writing a Ruby script to unzip a file where each pass through the %x{unzip } will have a different file name.
I have been successful getting
%x{unzip FILENAME.ZIP} to unzip the contents of FILENAME.ZIP
However, I want to be able to pass in the name of the file to unzip.
I've tried variations of
filename = "CONSTANT+variable+"NEXT_CONSTANT.ZIP"
%x{${filename}}
and I have been unable to get the %x to let me construct a filename that I want to unzip.

You can do it the same way you'd do it in a double-quoted string: #{filename}.
filename = "my_files.zip"
%x{unzip #{filename}}

Related

Get first file from a directory [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
I'm trying to get the full file path of a configuration file from a nested directory and only need the first result.
directory1/
├──directory2/
| └──configuration.ini
├──directory3/
| └──configuration.ini
What I want is to set only 1 file path to a variable.
e.g.
$ DIRECTORY=*/CODE*/
$ echo ${DIRECTORY};
$ /directory1/directory2/configuration.ini

File name too long bash [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
i want to copy some files from ../soft to ../copu_new. The name of that tests are in ../sim/soft.txt.
I had en error : cp:cannot stat '../soft/file1.txt\file2.txt\file3.txt': File too long
Follow the code below:
input="../sim/soft.txt"
while read line
do
##to skip the first line of the file
a=$(tail -n +1)
##From string to table
for i in $a
do
table_soft[$i]="$i"
done
for i in "${tabke_soft[#]}"
do
cp ../soft/$i ../copy_new
done
done < $input
The file Soft.txt is :
###This all tests:
file1.txt
file2.txt
file3.txt
It's most likely the classic bash issue where trying to run an array through a for loop gives you all the content unless you wrap it in double quotes first. Try this..
a="$(tail -n +1)"

How to remove leading / at each line a text file with sed Linux command [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
This is my text file and I want to remove every first line:
aaaa
bbbb/bbbb
/cccc/cccc
/Dddd/zzzz/wwww
.gggg
.oooo/sssss
/.vvvvv
!#%#/$%
How can I remove all first "/" from my text file?
I want the result text file to be like:
aaaa
bbbb/bbbb
cccc/cccc
Dddd/zzzz/wwww
.gggg
.oooo/sssss
.vvvvv
!#%#/$%
if it's any help, I'm using sed command.
sed can be instructed to replace the first / of each line with nothing:
sed 's_^/__' 'my text file name'

Howto rename bunch of filenames which are calculated [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want rename bunch of filenames. The rename is based on the calculation of the filename. That means the actual filename + 3600 = new filename.
Important is that the underscore in the pid files have to stay.
Thanks in advance!
My system is Debian Stretch.
Actual Filename:
134235.error
134235_.pid
134235.tiff
13893.error
13893_.pid
13893.tiff
1.error
1_.pid
1.tiff
Rename to:
137835.error
137835_.pid
137835.tiff
17493.error
17493_.pid
17493.tiff
3601.error
3601_.pid
3601.tiff
for fname in *; do
echo mv -- "$fname" "${fname/*[[:digit:]]/$((${fname%%[^[:digit:]]*}+3600))}"
done
If everything looks ok, remove echo.
With Perl's standalone rename command. Some distributions call it prename.
rename -n 's/(\d+)(.+)/${\($1+3600)}$2/' *
If everything looks fine, remove -n.

Adding header to tsv file through terminal [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have many tsv files that are headerless, and would like to add the same header to each of them. How can I do this through the terminal or bash?
Thanks!
sed -i '1i \here comes header' files
files could be glob exp, like *.txt
Assume you have header in "head", tsv files as "body", how about cat head body | tee body

Resources