Get first file from a directory [closed] - bash

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

Related

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'

Replacing dynamically changing regular expressions using sed [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 4 years ago.
Improve this question
,"some values1","some values2",Not Processed,0,
Is there any way I could replace the above pattern, irrespective of whatever values come in some values1 or some values2 with the lines below,
,,,Not Processed,0,
This string is just a part of a large file I have.
This solves the problem I believe:
test_data() {
cat <<EOF
,"val1,val2...","val1,val2,val3..",Not Processed,0,
,"val1,val2..","",Not Processed,0,
,"","val1,val2,val3....",Not Processed,0,
EOF
}
test_data | sed -e 's/\(.*\),"[^"]*","[^"]*",\(Not Processed,0,\)\(.*\)/\1,,,\2\3/g'
Output:
▶ bash data.sh
,,,Not Processed,0,
,,,Not Processed,0,
,,,Not Processed,0,

Substitution in %x command in Ruby [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 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}}

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