Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to replace specific number in a file Post 302448423 by dusoo on Thursday 26th of August 2010 03:10:48 AM
Old 08-26-2010
How to replace specific number in a file

Hi,

i'm trying to find a way to replace some numbers in a file, but with no luck sofar.

Let's say i have file with three columns,
i would like to find specific line, and replace third column with different number.
Code:
search_string="oa11 /home/testfile1.log"
new_number=600

test file contains two lines with three columns
Code:
oa11 /home/testfile1.log 100
oa11 /home/testfile2.log 200

changed file would be:
Code:
oa11 /home/testfile1.log 600
oa11 /home/testfile2.log 200

Im think i can do this using sed, but no clue how
Thanks for any tips.
D.

Moderator's Comments:
Mod Comment Use code tags please, ty.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Retain Only specific number of file in Directory

I want to retain specific number of backup files in a directory.for example i want to retain only two latest backup file in backup directory. If number of backup files is greater than this policy that it will delete oldest file.Please Tell me whether this is possible or not. (2 Replies)
Discussion started by: ranvijaidba
2 Replies

2. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

3. Shell Programming and Scripting

highly specific search and replace for a large number of files

hey guys, I have a directory with about 600 files. I need to find a specific word inside a command and replace only that instance of the word in many files. For example, lets say I have a command called 'foo' in many files. One of the input arguments of the 'foo' call is 'bar'. The word 'bar'... (5 Replies)
Discussion started by: ksubrama
5 Replies

4. Linux

Get a specific line number from a text file

Hello! All, Could you please tell me how to get a specific line number from a text file? For example below, ABC DEF ---> Get this line number, return to an variable GHI My OS is Linux. Thank you so much for your help in advance! (3 Replies)
Discussion started by: barryxian
3 Replies

5. UNIX for Dummies Questions & Answers

Comparing a number in a text file with a specific value

My project is to get a temperature reading from a refridgerator every 2 minutes and check to see if the door has been left open. I don't yet have the mastery of Linux, being a complete noob, but I reckon I need a text file with the latest temperature reading in it. This I've managed to do by... (2 Replies)
Discussion started by: Fitch
2 Replies

6. Shell Programming and Scripting

How to replace specific contents in a file?

From the existing file, I need to replace specific contents possibly with var every time when the user changes the var. e.g the contents in the file file.txt is 'My name is $n and I am $y years old' and every time user changed the var outside the file, the contents of the file should be created... (4 Replies)
Discussion started by: Emilywu
4 Replies

7. Shell Programming and Scripting

position specific replace in file

How to replace the position specific values in the file.. i searched a lot the forums but i couldn't able to do... i have file like below 576666666666666666666666666 7878 897987 121 0asdas Y12 5900fbb 777 09JJJ 78798347892374 234234234364 234232898 89HJHIHIGIUG989902743748327khjkhkjlh... (6 Replies)
Discussion started by: greenworld123
6 Replies

8. Shell Programming and Scripting

write specific line number in file

dear all, i need your advice i have sample script like this: testing.sh for i in {1..10} do echo testing $i done but i forgot create "#!/bin/bash" in above "for" so i want output will like this testing.sh #!/bin/bash for i in {1..10} do echo testing $i done (2 Replies)
Discussion started by: zvtral
2 Replies

9. Shell Programming and Scripting

Replace first number of each line in a file with another number

Hi, I have a set of files in a directory that I have to read and replace the first occurrence of a number with another dummy number. This is what I have so far but it does not seem to work. The files have lot of other data in each row and each data element is separated by ,@, for file in... (13 Replies)
Discussion started by: scorpioraghu
13 Replies

10. UNIX for Beginners Questions & Answers

Replace specific positions in a file

I have a fixed-length positional file. I am trying to replace content of position 4-13 (length=10) with xxxxxxxxxx. Sample 2 rows in this file: H0187459823 172SMITH, JOE H0112345678 172DOE, JANE In this example 87459823 (from 1st line) and 12345678 (from 2nd line) (both in position... (3 Replies)
Discussion started by: Diver181
3 Replies
mkcdsl(8)						      System Manager's Manual							 mkcdsl(8)

NAME
mkcdsl - Make a context-dependent symbolic link (CDSL) SYNOPSIS
/usr/sbin/mkcdsl [-bfnqv] [-i | -c | -a] [sourcename] [targetname] OPTIONS
All members. Copy the existing file or directory to a member-specific area on all members. Boot partition. In a cluster, the CDSL is placed on the boot partition. On a standalone system, an entry in added to the CDSL inventory file, and the CDSL will be created on the boot partition when the system is converted to a cluster by running clu_create. Copy the existing file or directory to a member-specific area on this member only. Force the overwriting of the existing CDSL or member-specific file or directory. When the force option is used with a copy option, mkcdsl will overwrite an existing member-specific file or directory. Without the force (-f) option, mkcdsl issues an error or message whenever the physical path of the target differs from the specified targetname (for example, when targetname resolution traverses a symbolic link), or when the source for a specified copy option cannot be found. Unless the -f option is specified, mkcdsl will exit when it encounters a situation that would generate an error message. The mkcdsl command issues a warning message if the specified sourcename differs from the calculated sourcename. However, you do not need the -f option to stop mkcdsl from exiting when it encounters a situation that generates a warning message. Inventory only. Check the files and update the inventory: If targetname is a CDSL, add a new entry or update the existing entry in /var/adm/cdsl_admin.inv. If targetname is not a CDSL or does not exist, remove its entry from /var/adm/cdsl_admin.inv. No execute mode. Display what would be done but do not create or change anything. Quiet. Stdout and stderr are redirected to /dev/null. Verbose. The pathname of the member-specific file to be linked. By default, each CDSL created by mkcdsl has a sourcename that points to the default member-specific area in the file system where the targetname resolves. For example, /usr/cluster/mem- bers/{memb}/ is the default member-specific area for the /usr file system. When issued without an explicit sourcename, mkcdsl creates a sourcename that points to this default member-specific area using a relative pathname. In most cases, this default behavior is satisfac- tory. It creates a relative link that resolves properly regardless of where the file system is mounted. If you specify a sourcename, mkcdsl uses this value as the pathname to the member-specific file or directory. The sourcename must include the member-context path compo- nent {memb}. The pathname of the new CDSL entry to be created. If targetname exists, the -f, -c or -a options are required. If the reso- lution of the targetname traverses any symbolic links or file system mount points, the default value of sourcename is adjusted such that the member-specific files are placed in the same file system to which targetname resolves. DESCRIPTION
A context-dependent symbolic link (CDSL) is a special form of a symbolic link, described in ln(1), whose target pathname includes a vari- able ({memb}). The value of {memb} is determined during pathname resolution, making it possible to maintain member-specific configuration and data files within the clusterwide namespace. The mkcdsl command creates a CDSL, effectively making the specified targetname file or directory member-specific. The command simplifies the creation of a CDSL by automatically calculating a default sourcename, which resolves to the default member-specific area in the file system where the CDSL is created. When mkcdsl creates a CDSL, it adds an inventory entry to a clusterwide CDSL inventory file, /var/adm/cdsl_admin.inv. This entry makes it possible for the cdslinvchk command to check CDSLs created by mkcdsl. The mkcdsl -i option updates the inventory file to reflect the cur- rent state of the CDSL by adding, modifying, or removing entries from the CDSL inventory file. In a cluster, when directed to put a file in a member-specific directory (-c or -a), mkcdsl populates both the member-specific directory or directories and the member0 directory. Although you can run mkcdsl from the command line, the mkcdsl command is designed to be non-interactive; it can be called from scripts without requiring user input to complete a task. EXAMPLES
To create a CDSL, /usr/testfile that points to cluster/members/{memb}/testfile: # mkcdsl /usr/testfile # ls -l /usr/testfile ... /usr/testfile -> cluster/members/{memb}/testfile In the previous example, /usr/testfile must not exist. The CDSL is created in /usr and no files are created in any member's /usr/clus- ter/members/{memb} directory. To copy the existing file or directory /usr/testfile1 to this member's /usr/cluster/members/membern directory and replace it with a CDSL that points to cluster/members/{memb}/testfile1: # mkcdsl -c /usr/testfile1 Although the CDSL references all members, only this member has a copy of the original /usr/testfile1 file. To copy the existing file or directory /usr/testfile2 to all members' /usr/cluster/members/{memb} directories and replace it with a CDSL that points to cluster/members/{memb}/testfile2: # mkcdsl -a /usr/testfile2 All members have a copy of the original /usr/testfile2 file. To create a CDSL and explicitly specify the sourcename: # mkcdsl /usr/share/cluster/members/{memb}/testfile3 /usr/share/doclib/testfile3 *** Warning *** The passed source name, '/usr/share/cluster/members/{memb}/testfile3' differs from the calculated source name: cluster/mem- bers/{memb}/testfile3 Using passed source name: '/usr/share/cluster/members/{memb}/testfile3' Because the specified sourcename differs from mkcdsl's calculated default value, the command issues a warning message. Note that mkcdsl makes the CDSL. The mkcdsl command does not exit on a warning message. It will exit for an *** Error *** message unless the -f option is specified. To add an inventory record for an existing CDSL to the /var/adm/cdsl_admin.inv file: # mkcdsl -i /etc/testfile4 To remove a CDSL and then remove its entry from the /var/adm/cdsl_admin.inv file: # rm /etc/testfile4 # mkcdsl -i /etc/testfile4 Note that removing the CDSL and its entry does not remove any files referenced by the CDSL. EXIT STATUS
The exit values for mkcdsl are: Success. Failure. FILES
Specifies the command path. CDSL administrative inventory file. This file will not exist on all systems. SEE ALSO
Commands: ln(1), cdslinvchk(8) Files: local(4) Miscellaneous: hier(5) mkcdsl(8)
All times are GMT -4. The time now is 03:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy