I'm using linux. Let's say I have a program named add. The program takes two numbers.
so if I type in
add 1 2
the answer is 3 //obvious
what command will make this write out to a file named add.data
I'm kind of a linux n00b. I was reading about piping. Thanks.
Piping means sending the output of a program as input to a second, which must be able to read data from the standard input, e.g.
add 1 2 | echo
What you are asking about here is output redirection: you should use
add 1 2 > add.data
to create a new file with your output (if existing will be overwritten), and
add 1 2 >> add.data
to create a new one or append to an existing.
add 2 3 > something.txt
This will redirect output into a file, recreates the file every time
add 1 2 > add.data
This will append to the end of the file
add 1 2 >> add.data
Related
I am using a unix based program. I want to automate the code so as not to copy and paste data one by one. For this, I need to define line-by-line data in a file as a variable for the code
The program converts xyz coordinates to local coordinates. How can I run the coordinates in the xyz_coordinates file I created, one by one, in the code below? In the program I use, the conversion code works like this:
echo 4208830.039709186 2334850.551667509 4171267.377406844 -6.753E-01 4.493E-01 2.849E-01 | xyz2env.py
and this is the file i am trying to run:
2679689.926729193 -727950.9964290063 5722789.538975053 7.873E-02 3.466E-01 6.410E-01
2679689.927123377 -727950.9971557076 5722789.540522 7.912E-02 3.458E-01 6.425E-01
2679689.930567728 -727950.9979971027 5722789.550832021 8.257E-02 3.450E-01 6.528E-01
2679689.931029495 -727950.9992263148 5722789.549927638 8.303E-02 3.438E-01 6.519E-01
2679689.929031829 -727950.9981009626 5722789.546359798 8.103E-02 3.449E-01 6.484E-01
........
and it goes on like this. Also, there are spaces between the lines. Will this be a problem?
You can use xargs to invoke the command for a specific number of arguments (6 in your case) and have the advantage of skipping empty lines automatically
< file.txt xargs -n 6 xyz2env.py
I already referred this post and post
I have my filenames like as shown below (1 set contains 3 related files). In my directory, I have 40 set of files (meaning 120 files). All the 40 sets have 3 files with same file extension
Set 1
Test_t5.version9.info.gz
Test_t5.version9.dose.vcf.gz.tbi
Test_t5.version9.dose.vcf.gz
Set 2
Test_t5.version12.info.gz
Test_t5.version12.dose.vcf.gz.tbi
Test_t5.version12.dose.vcf.gz
Only the version number in file changes across different sets.
Now, I would like to rename my files like as shown below
Set 1
Test_t5.version9.info.gz
Test_t5.version9.dose.vcf.gz.tbi
Test_t5.version9.dose.vcf.bgz #see the change here from `.gz to .bgz`
Set 2
Test_t5.version12.info.gz
Test_t5.version12.dose.vcf.gz.tbi
Test_t5.version12.dose.vcf.bgz #see the change here from `.gz to .bgz`
I tried the below but guess am making mistake while executing the command in the shell.
rename 's/dose.vcf.gz/dose.vcf.bgz/' Test_t5.version*.dose.vcf.gz
Basically modify the file extension for only one file in each of the set. You don't have to worry about Set 1 or Set 2. That was for you to understand that how our data is grouped.
Can you help please?
It looks like you are just wanting to do:
for file in *.vcf.gz; do mv "$file" "${file%.gz}.bgz"; done
I have this file named checkinout100.php and need to copy it to another 100 files following the numbered sequence like checkinout101.php, checkinout102.php and so on until 200.
I've been looking to do it with seq but can't figure it out on my own.
Thanks.
NOTE: Has nothing to do with webpages. It's an Asterisk PBX (Yeastar), I need one of those files per extension (link with hotel software).
You can use seq in the following way:
for n in $(seq 101 200) ; do
cp checkinout100.php checkinout$n.php
done
I have an api that returns 50 users.
Is there a way of looping through the api call
expand=users%5B1%3A50%5D
The 1 after B is the starting number and it will pull until 50 which is the number after A
I have a script that will store the responses to a text file but how can I loop through this adding increments of 50?
For example. having a variable in place of the numbers
expand=users%5B$num1%3A$num2%5D
expand=users%5B{1..50}%3A50%5D
The {1..5} will expand as 1 2 3 4 5
for example
$ echo abc{1..5}def
abc1def abc2def abc3def abc4def abc5def
now all you need is to loop over the expand
for api in $expand
do
#do something
done
I am running cygwin on Windows 7. I am using a signal processing tool and basically performing alignments. I had about 1200 input files. Each file is of the format given below.
input_file_ format = "AC_XXXXXX.abc"
The first step required building some kind of indexes for all the input files, this was done with the tool's build-index command and now each file had 6 indexes associated with it. Therefore now I have about 1200*6 = 7200 index files. The indexes are of the form given below.
indexes_format = "AC_XXXXXX.abc.1",
"AC_XXXXXX.abc.2",
"AC_XXXXXX.abc.3",
"AC_XXXXXX.abc.4",
"AC_XXXXXX.abc.rev.1",
"AC_XXXXXX.abc.rev.1"
Now, I need to use these indexes to perform the alignment. All the 6 indexes of each file are called together and the final operation is done as follows.
signal-processing-tool ..\path-to-indexes\AC_XXXXXX.abc ..\Query file
Where AC_XXXXXX.abc is the index associated with that particular index file. All 6 index files are called with **AC_XXXXXX.abc*.
My problem is that I need to use only the first 14 characters of the index file names for the final operation.
When I use the code below, the alignment is not executed.
for file in indexes/*; do ./tool $file|cut -b1-14 Project/query_file; done
I'd appreciate help with this!
First of all, keep in mind that $file will always start with "indexes/", so trimming first 14 characters would always include that folder name in the beginning.
To use first 14 characters in a variable, use ${file:0:14}, where 0 is the starting string index, and 14 is the length of the desired substring.
Alternatively, if you want to use cut, you need to run it in a subshell: for file in indexes/*; do ./tool $(echo $file|cut -c 1-14) Project/query_file; done I changed the arg for cut to -c for characters instead of bytes