Shell script - Replace just part of a single line in a file.....
Hey guy's....
I new here,
But im working on a school project, and I am not really good at programming. In fact, this is the only programming class that I need because programming is not what I am majoring in.
But I have everything done in this shell script except for this last part.....
Basically I have a file of an employee record book,
Formatted like so:
Firstname Lastname Phone OnCallDay
ex:
Henry Test 000-000-0000 Wed
There are more people in my file though. I have a shell script made to make changes to the record book. (add, delete records). But I need to add to my shell script, to let a person change a record's on call day.
It must only prompt the user for the person's name, and then the new on call day. It can not ask for the user's old on call day. So I really have no idea I would search for just a part of a line. Like is there is some way to just edit the last 3 characters of a given line?
Also two people cannot have the same on call day. (I have already figured this part out)
Here is that part of the script so far:
I know that I would start here by doing a grep to search for the person's line. But then I need to change the 3char on-call day of that line.....
Could anyone help me figure this last part out?
Any help would be greatly appreciated.....
Thanks a lot
Last edited by hxdrummerxc; 12-12-2012 at 09:57 PM..
That seems to do exactly what I wan't, it's just not writing it to the file (my file named phonebook).
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..
To write result to a file:-
Note: I am writing result to a temporary file: tmp and then I am renaming file: tmp back to file: phonebook. But I have commented out that line because first you have to check and verify if file: tmp is having desired result. If yes, then please un-comment it. I hope this helps.
To write result to a file:-
Note: I am writing result to a temporary file: tmp and then I am renaming file: tmp back to file: phonebook. But I have commented out that line because first you have to check and verify if file: tmp is having desired result. If yes, then please un-comment it. I hope this helps.
Ok that makes sense now. Yep that works.....
Thanks a lot!.... that was killing me
One last question, Say I have my record book formatted right now. Is it hard to make awk format/space each part out?
Like have the firstname span to 10 spaces, the last name span to 10 spaces etc?
I was able to do that earlier in my script file (the part where you could add a user to the file) by using:
So that way multiple different length names will space out the same....
Ex:
Henry Test 000-000-0000 Sun
Timothy Lastname 000-000-0000 Sun
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)