You are not logged in.
Pages: 1
I got the idea to create a bash alias to specify the number of concurrent gcc threads to run and that will take input along with the alias from the command line (ex. jobs 32), but im not really sure on how to do it. I have a slight grasp of sed but its pretty confusing to me, one of the main things I would like to know is how to edit a file in place (the inplace option in manual confuses me) because the only way I know how to do it now is like this:
echo day>day;sed 's/day/night/' <day >day1;mv day1 day
I think the command string I want for the alias to be something like this but im sure theres a cleaner/easier way to do it, and im not sure on the variable parts. I would like '5' and '15' to be replaced by variables, 5 being the current value of MAKEFLAGS=" -j" that is in /etc/makepkg.conf and with 15 being the input value, which IIRC would be $1
cd /etc; sed 's/MAKEFLAGS=" -j5"/MAKEFLAGS=" -j15"/" <makepkg.conf >makepkg.conf1; sudo mv makepkg.conf1 makepkg.conf
Last edited by brando56894 (2009-10-24 06:43:09)
Offline
I can help you with the first part:
echo day>day; sed -i -e 's/day/night/' day
Unfortunately that's about as far as my sed knowledge goes, someone else will surely know more.
Offline
cool, thanks.
Offline
You don't need the value of what it was, sed uses regexes. You can match whatever value was there with simply =.*
To get a variable in, you need to close sed's single quotes and then without spaces add double quotes so even if there are spaces in the variable, the variable is glued to the sed statement, and then resume the sed quote '. In this case you want to surround it inside the sed statement with extra double quotes so you get in the output.
sed -i '/^MAKEFLAGS/s/=.*/="'"$1"'"/' /etc/makepkg.conf
Offline
For a good guide, I like Gentoos' stream editor guide:
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
Just replacing the -j flag value:
#!/bin/bash
# send file to work on as first parameter and
# new value for -j as second parameter.
# example: thisscript file 22
sed -i "s/\(MAKEFLAGS=\"[^\"]*\-j\)[0-9]\+/\1$2/" $1
Last edited by tlvb (2009-10-24 13:42:02)
I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.
Offline
Thanks for the help, this is still extremely foreign to me though hopefully after I read that guide I'll understand it a little better.
You don't need the value of what it was, sed uses regexes. You can match whatever value was there with simply =.*
To get a variable in, you need to close sed's single quotes and then without spaces add double quotes so even if there are spaces in the variable, the variable is glued to the sed statement, and then resume the sed quote '. In this case you want to surround it inside the sed statement with extra double quotes so you get in the output.sed -i '/^MAKEFLAGS/s/=.*/="'"$1"'"/' /etc/makepkg.conf
using this I get the error that it cant write to a temp file:
sed: couldn't open temporary file /etc/sed1i1bQo: Permission denied
even though I added sudo to the alias sting:
alias jobs='sudo sed -i /^MAKEFLAGS/s/=.*/='\'''\''/ /etc/makepkg.conf'
Offline
Hmm, I think you should call the script something else than "jobs" though, as it is a bash alias showing what processes you have suspended and/or running in the background.
E.g:
$ vim foo
vim window opens, editing the file foo
ctrl+z
back at bash prompt, vim foo stopped[1]+ Stopped vim foo
$ vim bar
vim window opens, editing the file bar
ctrl+z
back at bash prompt, vim bar stopped[2]+ Stopped vim bar
$ jobs
[1]- Stopped vim foo
[2]+ Stopped vim bar
$ fg 2
the vim process editing the file bar is started again and brought forward
(bold stuff=user input, regular=appears as output, italics=describing the situation)
Last edited by tlvb (2009-10-24 17:31:08)
I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.
Offline
alias does not have $1 and such, use a function.
Offline
...Or make it a script with the appropirate hashbang and put it in a directory listed in $PATH
(I usually use /usr/bin)
I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.
Offline
I changed the name of the script to threads and its located in my ~/scripts directory. it works perfectly but I just needed to add in -j to the sed expression before the $1 variable or else it would just change MAKEFLAGS=-j[nunmber] to MAKEFLAGS=[number].
Thanks for the help and heres the whole script incase someone stumbles upon this thread and wants it.
#!/bin/bash
sudo sed -i '/^MAKEFLAGS/s/=.*/="'-j"$1"'"/' /etc/makepkg.conf
Offline
Pages: 1