Modify existing values in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modify existing values in a file
# 8  
Old 04-22-2014
I have tried below code and it is working but it is failing where there is no "kernel.shmall" parameter in file /etc/sysctl.conf
Code:
if grep -o "kernel.shmall" /etc/sysctl.conf > /dev/null
      then
            oldvalue=$(grep -v '^#' /etc/sysctl.conf|grep kernel.shmall|sed 's/=/ /g'| awk '{ print $2}')
      
            if [ $oldvalue -lt 4194304 ]
            then
               sed -i "s|\("kernel.shmall" *= *\).*|\14194304|" /etc/sysctl.conf
            fi
       else
           echo "kernel.shmall=" >> /etc/sysctl.conf
           sed -i "s|\("kernel.shmall" *= *\).*|\14194304|" /etc/sysctl.conf
      fi

is there any modifications do i need to do in script to add "kernel.shmall=4194304" value to file sysctl.conf where there is no parameter kernel.shmall
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pattern search and modify the values

I have one file and the file may contain 500 to 15,000 records. I need to search pattern ^F509= and then increment the corresponding value by one and print the entire line. Please note that Its not a fixed length file. Can anyone please help? ex: ^F509=204656 ^F509=204656 ... (6 Replies)
Discussion started by: vinus
6 Replies

2. Shell Programming and Scripting

Need to implement new CRON job or modify the existing one in MDM PROD in coming days, which will sen

Need to implement new CRON job or modify the existing one in MDM PROD in coming days, which will send email of SQL statement running from past 1 minute.Currently there is one CRON job in PROD, which send below email. there is one cron job which send email, when there is long running... (0 Replies)
Discussion started by: dampu
0 Replies

3. Shell Programming and Scripting

Adding columns with values dependent on existing columns

Hello I have a file as below chr1 start ref alt code1 code2 chr1 18884 C CAAAA 2 0 chr1 135419 TATACA T 2 0 chr1 332045 T TTG 0 2 chr1 453838 T TAC 2 0 chr1 567652 T TG 1 0 chr1 602541 ... (2 Replies)
Discussion started by: plumb_r
2 Replies

4. Shell Programming and Scripting

how to modify existing env var

greetings, i have the following env variable: LSB_HOSTS='t70cra102 t70cra102 t70cra108 t70cra108'the variable could be any number of host names and sometimes the same name several times. i was hoping there's a way to turn it into the following: NEW_LSB_HOSTS=,,,]always appreciate the help... (2 Replies)
Discussion started by: crimso
2 Replies

5. Shell Programming and Scripting

modify a file by inserting a conditional values

Hi, input file CCCC 1204 215764.85 9405410.40 1189 DDDD 4498 1503 4617 1507 4723 1517 4829 1528 4996 1540 DDDD 5199 1556 5278 1567 5529 1603 5674 1614 6076 1915 DDDD 6605 2371 7004 2779 CCCC ... (4 Replies)
Discussion started by: Indra2011
4 Replies

6. Shell Programming and Scripting

modify Existing MS excel workbook in perl

Hi I need to modify an excel file in perl and for which I installed perl in Linux 1. Open a existing excel file 2. delete an unwanted Sheet called "summary" 3. and i want to insert some data into range of cells ( B1:B11) 4. Remove unwanted value called "Sum" repeated in the... (1 Reply)
Discussion started by: luke_devon
1 Replies

7. Shell Programming and Scripting

insert pipes for existing and non-existing records

I have a source file like this, L4058S462 34329094 F51010141TK1070000483L4058S462 34329094 0232384840 381892 182 5690 L4058S462 34329094 F51020141FIRST CLEARING, LLC A/C 3432-9094 L4058S462 34329094 F51030141JOHAN HOLMQVIST ... (1 Reply)
Discussion started by: saravanamr
1 Replies

8. Solaris

Add existing user into an existing group

Pre: no gpasswd/adduser there is just usermod can be used, also there is no -a option for usermod. How should I add a user into a group? (4 Replies)
Discussion started by: a2156z
4 Replies

9. Shell Programming and Scripting

folder existing and file existing

I want to look into a folder to see if there are any folders within it. If there are, I need to check inside each folder to see if it contains a .pdf file So If /myserver/myfolder/ contains a folder AND that folder conatins a .pdf file do X Else do Z I may have multiple folders and... (4 Replies)
Discussion started by: crowman
4 Replies

10. UNIX for Advanced & Expert Users

How to modify an existing pdf with unix shell commands

Hi, I know that to create a pdf file I can use the txt2pdf command. But if I would change an existing pdf file, by inserting lines in particular positions of this file, what can I use? And How? (3 Replies)
Discussion started by: fandwick
3 Replies
Login or Register to Ask a Question
SYSCTL(8)						       System Administration							 SYSCTL(8)

NAME
sysctl - configure kernel parameters at runtime SYNOPSIS
sysctl [options] [variable[=value]] [...] sysctl -p [file or regexp] [...] DESCRIPTION
sysctl is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Procfs is required for sysctl support in Linux. You can use sysctl to both read and write sysctl data. PARAMETERS
variable The name of a key to read from. An example is kernel.ostype. The '/' separator is also accepted in place of a '.'. variable=value To set a key, use the form variable=value where variable is the key and value is the value to set it to. If the value contains quotes or characters which are parsed by the shell, you may need to enclose the value in double quotes. This requires the -w param- eter to use. -n, --values Use this option to disable printing of the key name when printing values. -e, --ignore Use this option to ignore errors about unknown keys. -N, --names Use this option to only print the names. It may be useful with shells that have programmable completion. -q, --quiet Use this option to not display the values set to stdout. -w, --write Use this option when you want to change a sysctl setting. -p[FILE], --load[=FILE] Load in sysctl settings from the file specified or /etc/sysctl.conf if none given. Specifying - as filename means reading data from standard input. Using this option will mean arguments to sysctl are files, which are read in order they are specified. The file argument can may be specified as reqular expression. -a, --all Display all values currently available. --deprecated Include deprecated parameters to --all values listing. -b, --binary Print value without new line. --system Load settings from all system configuration files. /run/sysctl.d/*.conf /etc/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf /etc/sysctl.conf -r, --pattern pattern Only apply settings that match pattern. The pattern uses extended regular expression syntax. -A Alias of -a -d Alias of -h -f Alias of -p -X Alias of -a -o Does nothing in favour of BSD compatibility. -x Does nothing in favour of BSD compatibility. -h, --help Display help text and exit. -V, --version Display version information and exit. EXAMPLES
/sbin/sysctl -a /sbin/sysctl -n kernel.hostname /sbin/sysctl -w kernel.domainname="example.com" /sbin/sysctl -p/etc/sysctl.conf /sbin/sysctl -a --pattern forward /sbin/sysctl -a --pattern forward$ /sbin/sysctl -a --pattern 'net.ipv4.conf.(eth|wlan)0.arp' /sbin/sysctl --system --pattern '^net.ipv6' DEPRECATED PARAMETERS
The base_reachable_time and retrans_time are deprecated. The sysctl command does not allow changing values of there parameters. Users who insist to use deprecated kernel interfaces should values to /proc file system by other means. For example: echo 256 > /proc/sys/net/ipv6/neigh/eth0/base_reachable_time FILES
/proc/sys /etc/sysctl.conf SEE ALSO
sysctl.conf(5) regex(7) AUTHOR
George Staikos <staikos@0wned.org> REPORTING BUGS
Please send bug reports to <procps@freelists.org> procps-ng Jan 2012 SYSCTL(8)