Adding header to tsv file through terminal [closed] - bash

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

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

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'

how to sed for certain parts of a string by delimiter [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
I have lots of different strings that look like redhat-ubi-ubi7-7.8
I want to use the string to make variables so that I end up having something like
vendor=redhat
product=ubi
image=ubi7
tag=7.8
How can I do this?
With bash and a here string:
string='redhat-ubi-ubi7-7.8'
IFS=- read -r vendor product image tag <<< "$string"
echo "$vendor"
Output:
redhat
Using P.E. parameter expansion.
string='redhat-ubi-ubi7-7.8'
vendor=${string%%-*}
tag=${string##*-}
image=${string%-*}
product=${image#*-}
product=${product%-*}
image=${image##*-}
printf '%s\n' vendor=$vendor product=$product image=$image tag=$tag
Output
vendor=redhat
product=ubi
image=ubi7
tag=7.8

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.

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}}

Resources