Sponsored Content
Top Forums Shell Programming and Scripting Shell script - Replace just part of a single line in a file..... Post 302743449 by hxdrummerxc on Wednesday 12th of December 2012 09:41:43 PM
Old 12-12-2012
Quote:
Originally Posted by bipinajith
Use awk:-
Code:
awk -v N=$name -v D=$newday '$0 ~ N { $NF=D; print $0; } ' record_book_file

Thanks for the reply, Smilie

That seems to do exactly what I wan't, it's just not writing it to the file (my file named phonebook).

Code:
echo "Enter the name of the employee, to change their on-call day: "
read name
echo "enter new on call day: "
read newday
days=`grep $newday phonebook | wc -l`   #This is to check availability day
if [ $days -ne 0 ]
then
   echo "Sorry there is already an employee on call for that day"
   exit
else
   awk -v N=$name -v D=$newday '$0 ~ N { $NF=D; print $0 } ' phonebook
fi
echo "Success";;


I changed the on call day from Wed to Sun and it came up and showed
Henry Test 000-000-0000 Sun
But it didn't write it to the file. Im not familiar with awk, but could I make the awk line a variable to use to add to the file?
like:
add = awk -v N=$name ..... etc
echo "$add" >> phonebook

or would that not work?

Last edited by hxdrummerxc; 12-12-2012 at 10:52 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how to replace a line in a file using shell script

I have a property file in which the DB name is specified and when i run my servers they will point to the DB specified in that property file. Now i'm gonna write a script which will start all the services. But before that i just want to dynamically change the DB name in that property file by... (3 Replies)
Discussion started by: cs_sakthi
3 Replies

2. Shell Programming and Scripting

how can i replace / with new line in shell script or sed ?

1. how can i replace ' / ' with new line in shell script or sed ? 2. how can set a conditon untill null in while loop while ( i== null ) do ...... done (3 Replies)
Discussion started by: mail2sant
3 Replies

3. UNIX for Dummies Questions & Answers

replace part of single string in a file

hi! i have a file consisting of the following lines: (BTW, = space) . . . 12ME_T1mapping_flip30bshortf 13DCE_whole_brainbshortf 13DCE_3Dbshortf . . . the list of scans starts at 1 and goes on sometimes up to 60 scans. i would like to change only the lines that contain 'whole' to... (2 Replies)
Discussion started by: nixjennings
2 Replies

4. Shell Programming and Scripting

replace space or spaces in a line of a file with a single :

I am searching while I await a response to this so if it has been asked already I apologize. I have a file with lines in it that look like: bob johnson email@email.org I need it to look like: bob:johnson:email@email.org I am trying to use sed like this: sed -e 's/ /:/g' file >... (5 Replies)
Discussion started by: NewSolarisAdmin
5 Replies

5. Shell Programming and Scripting

shell script to find and replace a line using a identifier

Hi all im having trouble starting with a shell script, i hope someone here can help me i have 2 files file1: 404905.jpg 516167 404906.jpg 516168 404917.psd 516183 404947.pdf 516250 file2: 516250 /tmp/RecyclePoster18241.pdf 516167 /tmp/ReunionCardFINAL.jpg 516168... (7 Replies)
Discussion started by: kenray
7 Replies

6. Shell Programming and Scripting

Script to multiple find and replace in a single file

Dear all I need a script for multiple find and replace in a single file. For example input file is - qwe wer ert rty tyu asd sdf dgf dfg fgh qwe wer det rtyyui jhkj ert asd asd dfgd now qwe should be replace with aaaaaa asd should be replace with bbbbbbbb rty should be replace... (6 Replies)
Discussion started by: wildhorse
6 Replies

7. Shell Programming and Scripting

replace part of text of a line

Gurus, You know, I believe you do:-), the comnand uname -r give you the kernel version: serverA:~# uname -r 2.6.26-1-xen-amd64So, I want to replace this output inside in the line below that is inside the file: kernel = '/boot/vmlinuz-2.6.26-1-xen-amd64'Suppose, you move this file to ther... (2 Replies)
Discussion started by: iga3725
2 Replies

8. Shell Programming and Scripting

Single/Multiple Line with Special characters - Find & Replace in Unix Script

Hi, I am creating a script to do a find and replace single/multiple lines in a file with any number of lines. I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE print $FIND gives Hi How r $u Rahul() Note:... (0 Replies)
Discussion started by: r_sarnayak
0 Replies

9. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

10. UNIX for Beginners Questions & Answers

Merge multi-lines into one single line using shell script or Linux command

Hi, Can anyone help me for merge the following multi-line log which beginning with a " and line ending with ": into one line. *****Original Log***** 087;2008-12-06;084403;"mc;;SYHLR6AP1D\LNZW;AD-703;1;12475;SYHLR6AP1B;1.1.1.1;0000000062;HGPDI:MSISDN=12345678,APNID=1,EQOSID=365;... (3 Replies)
Discussion started by: rajeshlinux2010
3 Replies
OCF_HEARTBEAT_SFEX(7)						OCF resource agents					     OCF_HEARTBEAT_SFEX(7)

NAME
ocf_heartbeat_sfex - Manages exclusive access to shared storage using Shared Disk File EXclusiveness (SF-EX) SYNOPSIS
sfex [start | stop | monitor | meta-data | validate-all] DESCRIPTION
Resource script for SF-EX. It manages a shared storage medium exclusively . SUPPORTED PARAMETERS
device Block device path that stores exclusive control data. (required, string, no default) index Location in block device where exclusive control data is stored. 1 or more is specified. Default is 1. (optional, integer, default 1) collision_timeout Waiting time when a collision of lock acquisition is detected. Default is 1 second. (optional, integer, default 1) monitor_interval Monitor interval(sec). Default is 10 seconds (optional, integer, default 10) lock_timeout Valid term of lock(sec). Default is 100 seconds. The lock_timeout is calculated by the following formula. .sp lock_timeout = monitor_interval + "The expiration time of the lock" .sp We suggest 90 seconds as a default value of the "The expiration time of the lock", but you should change it in consideration of access delay to the shared disk and the switch time of the multipath driver. .sp The lock timeout have an impact on start action timeout because start action timeout value is calculated by the following formula. .sp start timeout = collision_timeout + lock_timeout + "safety margin" .sp The "safety margin" is decided within the range of about 10-20 seconds(It depends on your system requirement). (optional, integer, default 100) SUPPORTED ACTIONS
This resource agent supports the following actions (operations): start Starts the resource. Suggested minimum timeout: 120s. stop Stops the resource. Suggested minimum timeout: 20s. monitor Performs a detailed status check. Suggested minimum timeout: 10s. Suggested interval: 10s. meta-data Retrieves resource agent metadata (internal use only). Suggested minimum timeout: 5s. validate-all Performs a validation of the resource configuration. Suggested minimum timeout: 5s. EXAMPLE
The following is an example configuration for a sfex resource using the crm(8) shell: primitive p_sfex ocf:heartbeat:sfex params device=string op monitor depth="0" timeout="10s" interval="10s" SEE ALSO
http://www.linux-ha.org/wiki/sfex_(resource_agent) AUTHOR
Linux-HA contributors (see the resource agent source for information about individual authors) resource-agents UNKNOWN 03/09/2014 OCF_HEARTBEAT_SFEX(7)
All times are GMT -4. The time now is 07:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy