I have a file that is similar to this:
<many lines of stuff>
SUMMARY:
<some lines of stuff>
END OF SUMMARY
I want to extract just the stuff between SUMMARY and END OF SUMMARY. I suspect I can do this with sed but I am not sure how. I know I can modify the stuff in between with this:
sed "/SUMMARY/,/END OF SUMMARY/ s/replace/with/" ...
I want to extract a substring matching a pattern and save it to a file. An example string:
Apr 12 19:24:17 PC_NMG kernel: sd 11:0:0:0: [sdf] Attached SCSI removable disk
I want to extract the part between the brackets, in this case [sdf].
I tried to do something like grep -e '[$subtext]' to save the text in the brackets to a variable...
Hi all
i have a file like this:
term1 term2
term3 term4
term2 term1
term5 term3
..... .....
what i need to do is to remove duplicates in any order they appear, such as:
term1 term2
and
term2 term1
is a duplicate to me.
It is a really long file, so I'm not sure what can be faster.
Does anyone has an idea on how to do this? awk...
I'm trying to write some code in bash which uses introspection to select the appropriate function to call.
Determining the candidates requires knowing which functions are defined. It's easy to list defined variables in bash using only parameter expansion:
$ prefix_foo="one"
$ prefix_bar="two"
$ echo "${!prefix_*}"
prefix_bar prefix_foo...
Is there a Linux utility of a bash command I can use to sort a space delimited string of numbers?
...
I'm writing a mock-grading script in bash. It's supposed to execute a C program which will give some output (which I redirect to a file.) I'm trying to (1) make it timeout after a certain duration and also (2) terminate if the output file reaches a certain file size limit. Not sure how to go about either of these. Any help? Thanks.
...
The mark " in Vim takes you to your last cursor position. I want to create an alias that will open my Vim instance and jump to that mark; something which is obviously extremely useful.
This works from the command line:
$ vim -c "'\"" File.cpp
Now I want to make an alias for this:
$ alias v='vim -c "'\""'
Well that's not goin...
x=1
c1=string1
c2=string2
c3=string3
echo $c1
string1
I'd like to have the output be string1 by using something like:
echo $(c($x))
So later in the script I can increment the value of x and have it output string1, then string2 and string3.
Can anyone point me in the right direction?
...
Run a recursive listing of all the
files in /var/log and redirect
standard output to a file called
lsout.txt in your home directory.
Complete this question WITHOUT leaving
your home directory.
An: ls -R /var/log/ >
/home/bqiu/lsout.txt
I reckon the above bash command is not correct. Because I found what it store...
I am trying to call ssh-keygen using a variable through bash as an input instead of a file to get a fingerprint of a public key. I am aware that I could use a temp file to get around this issue, but for reasons out of scope of this question, I do not want to.
This method does not work as it says the key file is invalid (it's correct fo...
Hello,
I would like to export the Bash Shell Automation Script Project to a GUI Project which can run in both Windows and Linux.
Which Programming Language would be better suited for this ? Any suggestion would be really helpful.
Thanks
Kiran
...
I have a file, with n numbers on each lines. The first column on the line is a date: say 12/31/2009. However, some dates can be missing. I want to create files corresponding to date, containing the numbers that follow. For example:
master file will contain this data:
12/28/2009 5 6 7
12/31/2009 6 7 7
The resulting files s...
How do I get the last non-empty line using tail under Bash shell?
For example, my_file.txt looks like this:
hello
hola
bonjour
(empty line)
(empty line)
Obviously, if I do tail -n 1 my_file.txt I will get an empty line. In my case I want to get bonjour. How do I do that?
...
I'd like to be able to switch temporarily from emacs mode to vi mode, since vi mode is sometimes better, but I'm usually half-way through typing something before I realize I want
I don't want to switch permanently to vi mode, because I normally prefer emacs mode on the command line, mostly because it's what I'm used to, and over the yea...
I often have a command that processes one file, and I want to run it on every file in a directory. Is there any built-in way to do this?
For example, say I have a program data which outputs an important number about a file:
./data foo
137
./data bar
42
I want to run it on every file in the directory in some manner like this:
map da...
In Bash script, what is the difference between the following snippets?
1) Using single brackets:
if [ "$1" = VALUE ] ; then
# code
fi
2) Using double brackets:
if [[ "$1" = VALUE ]] ; then
# code
fi
...
I need to read a value from the terminal in a bash script. I would like to be able to provide a default value that the user can change.
# Please enter your name: Ricardo^
In this script the prompt is "Please enter your name: " the default value is "Ricardo" and the cursor would be after the default value. Is there a way to do this i...
I want to know if there is a built-in BASH command that prints some text on stderr, just like the echo command that prints text on stdout. I don't want to use temporary io-redirection. I use a built-in command to generate an error on stderr such as ls --asdf (ls: unrecognized option '--asdf') but I want something neater.
Edit ----
Actu...
I'm writing a bash script that encrypts the data of a folder or file
#!/bin/bash
file_name=$1
tmp_file=/tmp/tmpfile.tar
# tar compress file
tar -cf $tmp_file $file_name;
# encrypt file
gpg -c $tmp_file
# remove temp file
rm -rf $tmp_file $file_name
# mv encrypted file to orignal place
mv ${tmp_file}.gpg $file_name
but the data wi...
I'm launching an EC2 instance, by invoking ec2-run-instances from simple a bash script, and want to perform further operations on that instance (e.g. associate elastic IP), for which I need the instance id.
The command is something like ec2-run-instances ami-dd8ea5a9 -K pk.pem -C cert.pem --region eu-west-1 -t c1.medium -n 1, and its o...