is it possible to save all the output from a created bash shell file?
Basically the file makes calculations and I would like to save all the output of this created bash shell.
Basically I want to save all the output to a file or sample the last 10 outputs (for example)
$ ./yourscript.sh > outputfile.txt
Where yourscript.sh is the bash shell file you've created and outputfile.txt is the file you want to write the output to.
Related
I am trying to pull all the information to a log file using:
this is written inside my bash script.
exec >> (tee -a "$log")
but this actually shows all the output and brings all the information to the log file.
can you don't show 1 line of the output inside the bash script?
I want to write a bash script which copies the last line containing a particular string from a bunch of similarly named files to a new file.
For example I have three files: 1abc1.txt, 2abc2.txt and 3abc3.txt.
From these three files i want to extract the last line containing the term "pass" and write those extracted lines to a new file named "ABC.txt".
The following is the bash script I came up with: (pass.sh)
#!/bin/bash
grepline pass "$1" 1 > $2
Then I issued the following command:
./pass.sh *abc*.txt ABC.txt
But it doesn't create the ABC.txt file. Instead it scans for the string "pass" only in 1abc1.txt and then writes the output to 2abc2.txt .
I am supposing that my use of wild cards while issuing the command is not correct. Please can anyone suggest how to achieve what I want to do with the script?
The wildcards are expanded by the shell before your script is executed, so actually you execute
./pass.sh 1abc1.txt 2abc2.txt 3abc3.txt ABC.txt
If you need to pass wildcards to your script you should quote this argument, and then let the shell expand it within the script
./pass.sh '*abc*.txt' ABC.txt
and the script should contain
grepline pass $1 1 > $2
Hi I am using this script named analysis.sh
#!/bin/bash
SAMPLENAME=$1;
SAVEDATA=$2;
DATAPATH=$3;
REFERENCE=$4
......
I want to give input of multiple files in CSV format instead of putting individual files details every time as to multiple files can be parsed through single script.
e.g. i have two files ABC and XYZ
so in order to analyse these two files i give these commands
For ABC
analysis.sh ABC /home/myfolder1 /home/datafolder1 /home/referncefolder1
and for XYZ
analysis.sh XYZ /home/myfolder2 /home/datafolder2 /home/referncefolder2
if i have 100 different files, how to use a single CSV file with details of these 100 files in it that can be parsed through the command line arguments of this bash script?
You can pass the name of the csv file as a single argument and have your script read it line by line:
csv=$1
while IFS=, read -r filename savedata datapath reference; do
# do the processing
done < "$csv"
See this post to understand more about how to read a text file in Bash:
Looping through the content of a file in Bash
You may want to read more about the shell variable naming convention:
Correct Bash and shell script variable capitalization
I am trying to make a script that will ask you for a path to several files when you set it up and when you run the actual script, it reads the path from a file that you created earlier. I can make the file, I just need to know how to take that path and use it in the current script.
ex.
Settings
/home/user/launcher
Launcher
cat Settings
read PathToLaunchers
cd \$PathToLaunchers
read pathToFiles
for f in $pathToFiles
do
cat $f
done
I am just printing the contexts of each file entered in pathToFiles. You can replace cat command with the command you are interested.
If pathToFiles has only one line (i.e. only one filename), then you dnt need the for loop and just use cat $pathToFiles
I'm trying to write a shell script that builds an iso image from an .asm file with several utilities. When you run the script from the command line it first asks the user where the file is and where the iso file should be. I want the script accept arguments the user passed as part of the command: ./mkiso foo.iso bar.asm? The two arguments would correspond to two variables, input and output. How do I do this? EDIT: I'm using Linux and my script is a bash script.
mkiso:
#!/bin/bash
input=$1
output=$2
echo "input: $input, output: $output"
Run it with parameters
./mkiso aa.iso bb.asm
Output
input: aa.iso, output: bb.asm