Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Replacing values inside a file. Post 303040376 by asdfghjkl on Monday 28th of October 2019 07:18:15 AM
Old 10-28-2019
Replacing values inside a file.

Good day guys,

I'm having trouble in creating a logic when it comes to replacing the values inside a file.
I tried using sed command but it just doesn't work the way I want it to be.

Here is what I'm trying to achieve.

If my input file contains the values below.
Code:
NAME++GUEST1  ++GUESS2++

And I want to replace "GUEST1 " with "GUEST" without changing the number of characters placed on that field. Meaning if the segment has 10 characters, it will still remain 10 characters regardless of the value placed.

Is this possible?

Thank you so much in advance for any tips and recommendations.

Last edited by vbe; 10-28-2019 at 09:46 AM.. Reason: typos, code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in sed command ( Replacing a pattern inside a file with a variable value )

Hello, The following sed command is giving error sed: -e expression #1, char 13: unknown option to `s' The sed command is echo "//-----" | sed "s/\/\/---*/$parChk/g" where parChk="//---ee-" How can i print the variable value from sed command ? And is it possible to replace a... (2 Replies)
Discussion started by: frozensmilz
2 Replies

2. Shell Programming and Scripting

Replacing File values

Currently I am using the tr command in 3 scenarios for a ksh script. 1) Replacing any spaces in the file with a ~ tr ' ' '~' <$orignalFile> $newFile 2) After certain processing is done at the end of the scirpt i convert the Tilde back to spaces tr ' ' '~' <$newFile> $newFile2 3) Last... (4 Replies)
Discussion started by: hgjdv
4 Replies

3. Shell Programming and Scripting

Replacing text inside xmltag

Hi All- I have a xml file with tag <Forename>ABCDEF</Forename> <Surname>ABCDEFGH</Surname> in between tag it could be anything I need to search <Forename></Forename> and change what ever there in between Regards, Sreejit (1 Reply)
Discussion started by: sreejitnair123
1 Replies

4. Shell Programming and Scripting

Replacing values in a file based on values in another file

Hi I have 2 files:- 1. List of files which consists of names of some output files. 2. A delimited file; delimted by "|" I want to replace the value of the $23 (23rd column) in the delimited file with name in the first file. It is always position to position. Meaning first row of the first... (5 Replies)
Discussion started by: pparthiv
5 Replies

5. Shell Programming and Scripting

Replacing column 1 in one file with values in other file

Please help me with an shell / awk script to achieve following; File-1: ABCDW01 12322 23322 BDADW01 22232 24453 EDFAW00 32232 23422 and so on, notice that the first coloumn is a code and the another file contains the real value of each entry in the first colum above but not in a... (4 Replies)
Discussion started by: digipak
4 Replies

6. UNIX for Dummies Questions & Answers

Issue with use of Configuration file instead of hardcoded values inside the script

Hi, My code works perfectly fine. But, $my $min_to_add = 1 * 1 * 60; and my $hr_to_sub = 1 * 1 * 86400; i may need to change the values in future. so am keeping them in a separate configuration file like MIN = 1 * 1 * 60 HR = 24 * 60 * 60 in the script, i use a package use et_config... (3 Replies)
Discussion started by: irudayaraj
3 Replies

7. Shell Programming and Scripting

Replacing string values from a File

I want to replace string values from a file to a file For eg : File1 has 30 lines of string with values, those specific values needs to be changed in file2 and remaining values in file2 should be as it is. For example: From file (File1) cluster.name=secondaryCluster To replace File... (9 Replies)
Discussion started by: sriram003
9 Replies

8. Shell Programming and Scripting

Taking sum up all values inside the file

Hi, Taking sum up all values inside the file by using the below command: paste -sd+ filenmae | bc Getting some error like "0705-001: building space exceeded on line1 stdin" The original data looks like SPACE SPACE SPACE 0.123 JOBNAME1 SPACE SPACE 20.325 JOBNAME2 SPACE SPACE... (2 Replies)
Discussion started by: NareshN
2 Replies

9. Shell Programming and Scripting

Finding the pattern and replacing the pattern inside the file

i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of value abc and ccc in the place of them. Input File: go to &abc=ddd; if... (16 Replies)
Discussion started by: saaisiva
16 Replies

10. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies
tr(1)							      General Commands Manual							     tr(1)

Name
       tr - translate characters

Syntax
       tr [-cds] [string1[string2]]

Description
       The  command copies the standard input to the standard output with substitution or deletion of selected characters.  Input characters found
       in string1 are mapped into the corresponding characters of string2.  When string2 is short it is padded to the length of string1 by  dupli-
       cating  its  last character.  Any combination of the options -cds may be used: -c complements the set of characters in string1 with respect
       to the universe of characters whose ASCII codes are 0 through 0377 octal; -d deletes all input  characters  in  string1;  -s  squeezes  all
       strings of repeated output characters that are in string2 to single characters.

       In  either string the notation a-b means a range of characters from a to b in increasing ASCII order.  The backslash character () followed
       by 1, 2 or 3 octal digits stands for the character whose ASCII code is given by those digits.  A  followed by any other  character  stands
       for that character.

       The  following  example creates a list of all the words in `file1' one per line in `file2', where a word is taken to be a maximal string of
       alphabetics.  The second string is quoted to protect  from the Shell.  012 is the ASCII code for newline.
       tr -cs A-Za-z '12' <file1 >file2

Options
       -c   Translates complements:  string1 to those not in string1.

       -d   Deletes all characters in string1 from output.

       -s   Squeezes succession of a character in string1 to one in output.

Restrictions
       `', `0', and `00' are equivalent for NUL character.

       `12' is treated as octal 12 and not a NUL followed by characters 1 and 2.

See Also
       ed(1), ascii(7), expand(1)

																	     tr(1)
All times are GMT -4. The time now is 08:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy