Sponsored Content
Top Forums Shell Programming and Scripting Shell script - Replace just part of a single line in a file..... Post 302743455 by hxdrummerxc on Wednesday 12th of December 2012 10:03:51 PM
Old 12-12-2012
Quote:
Originally Posted by bipinajith
To write result to a file:-
Code:
awk -v N=$name -v D=$newday '$0 ~ N { $NF=D; print $0 } $0 !~ N { print $0 } ' phonebook > tmp
# mv tmp phonebook

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:

Code:
first=$(printf "%-16s" $first)
last=$(printf "%-13s" $last)

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


EDIT: Once again, thank you!
 

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
GSMPB(8)						      System Manager's Manual							  GSMPB(8)

NAME
gsmpb - GSM mobile phone phonebook manipulation program SYNOPSIS
gsmpb [ -b baudrate ] [ --baudrate baudrate ] [ -c ] [ --copy ] [ -d destination device or file ] [ --destination destination device or file ] [ -h ] [ --help ] [ -i ] [ --index ] [ -I init string ] [ --init init string ] [ -p phonebook name ] [ --phonebook phonebook name ] [ -s source device or file ] [ --source source device or file ] [ -t character set ] [ --charset character set ] [ -v ] [ --version ] [ -V ] [ --verbose ] [ -X ] [ --xonxoff ] [ -y ] [ --synchronize ] DESCRIPTION
gsmpb can store or retrieve phonebook entries residing in a GSM mobile phone's phonebook to or from a file. A synchronization mode is also available. gsmpb reads entries from the source which can be a mobile phone (if a serial device file is given) or a file (if a file name is given). The source is never modified. gsmpb writes phonebook entries to a destination file or device. Depending on the mode the source is copied to the destination file, thus overwriting the destination, or the destination is synchronized with regard to the source which is the default (details see below). If "-" is given as the parameter for the --source or --destination options, the phonebook is read from standard input and/or written to standard output, respectively. Phonebook entries names are encoded using the GSM default alphabet in the mobile phone, whereas they are stored using the Latin-1 encoding in phonebook files. When reading phonebook entries from a mobile phone entry names are converted from the GSM default to Latin-1. Charac- ters that can not be converted to Latin-1 are encoded as character code 172 (Latin-1 boolean "not"). When writing file-based phonebook entries to a mobile phone a conversion to the GSM default alphabet takes place. Characters that can not be converted are encoded as GSM delta (code 16). If the default character set has been changed using the --charset option no conversion takes place. Error messages are printed to the standard error output. If the program terminates on error the error code 1 is returned. OPTIONS
-b baudrate, --baudrate baudrate The baud rate to use. The default baudrate is 38400. -c, --copy This causes the contents of the source to be copied to the destination. After this operation the destination has exactly the same contents as the source. -d destination, --destination destination The destination device or file. -h, --help Prints an option summary. -I init string, --init init string Initialization string to send to the TA (default: "E0"). Note that the sequence "ATZ" is sent first. -i, --index If the index position is given, gsmpb preserves the assignment of entries to memory slots in the mobile phone's phonebook. This can be used to backup phonebook entries with their position into a phonebook file or to change the position of entries by editing a phonebook file and writing them back to the mobile phone. If this option is given the phonebook file used as the source must con- tain indices for every entry. Additionally, these indices must be unique, ie. it is not allowed to assign one entry twice to a spe- cific position in the mobile phone's phonebook. -p phonebook, --phonebook phonebook The name of the phonebook to read from or write to. This is only used for device sources and destinations. Commonly available phone- books are: FD SIM fixdialling-phonebook LD SIM last-dialling-phonebook ME ME phonebook MT combined ME and SIM phonebook SM SIM phonebook TA TA phonebook -s source, --source source The source device or file. -t character set, --charset character set Set the character set to use for phonebook operations (default is the GSM default alphabet). -v, --version Prints the program version. -V, --verbose Prints out a detailed progress report. -X, --xonxoff Uses software handshaking (XON/XOFF) for accessing the device. -y, --synchronize This causes the contents of the source to be synchronized with the destination (default). Synchronization in this con- text means: - If the source contains an entry with a name that does not exist in the destination this entry is added to the desti- nation. - If the source contains an entry with a name that can also be found in the destination, the entry in the destination is overwritten (ie. the telephone number is updated). Exception: More then one entry with the name exists in the destination. In this case the new entry ist just added. - Entries in the destination that do not exist in the source are deleted. Note that synchronization has the following properties that differ from copying: This algorithm does not change the location of unchanged entries in the destination phonebook. The synchronization function is not case-sensitive when comparing names. PHONEBOOK FILE FORMAT
Phonebook entries are stored in phonebook files that are meant to be human-readable and -editable. There is one phonebook entry per line, and each line has the format: index|text|phone number The fields have the following meanings: index The index of the entry which must be a positive number. The index may also be empty. Indices can be used in conjunction with the --index option to store the entry into a specific position in the mobile phone. text Descriptive text for the entry. The text may con- tain the special characters '', '|', carriage return (ASCII code 13), or line feed (ASCII code 10). These must be written "\", "|", " ", " ", respectively. The text should only contain charac- ters that can be encoded using the GSM default alphabet (see comments above). phone number Phone numbers can only contains the digits 0-9 and the '+' sign. A '+' sign denotes an international number. EXAMPLES
The following invocation of gsmpb synchronizes the mobile phone's SIM phonebook with the file $HOME/.phonebook: gsmpb --synchronize -b 19200 -d /dev/mobilephone -s $HOME/.phonebook -p "SM" AUTHOR
Peter Hofmann <software@pxh.de> BUGS
Report bugs to software@pxh.de. Include a complete, self- contained example that will allow the bug to be repro- duced, and say which version of gsmpb you are using. COPYRIGHT
Copyright (C) 1999 Peter Hofmann gsmpb is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Pub- lic License as published by the Free Software Foundation; either version 2, or (at your option) any later version. gsmpb is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied war- ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR- POSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with gsmpb; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. SEE ALSO
gsminfo(7), gsmctl(1), gsmsendsms(1), gsmsmsd(8), gsmsms- store(1). gsmpb v1.10 Sat Jun 16 22:10:00 UTC 2012 GSMPB(8)
All times are GMT -4. The time now is 03:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy