Sponsored Content
Top Forums Shell Programming and Scripting Searching for a particular string and modifying text within block of data Post 302472960 by pchang on Thursday 18th of November 2010 02:43:06 PM
Old 11-18-2010
Searching for a particular string and modifying text within block of data

Hi Forum.

Is there a quick way to do the following search/replace within a block of data? I tried to google the solution but didn't really know what to look for.

I have the following text file (I want to search for a particular string "s_m_f_acct_txn_daily_a1" and replace the "$$startdate=to_char(sysdate-10,'j')" to "$$startdate=to_char(sysdate-10000,'j')" within that data block only (Appending 3 zeroes at end).

Everything else should remain as is.

Process should ask for a particular string to search for.

Code:
Original Text:
[s_m_f_acct_txn]
$PMSessionLogFile=$PMRootDir/Logs/AUTO.S_M_F_ACCT_TXN.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10,'j')
$$enddate=to_char(sysdate, 'j')
 
 
[s_m_f_acct_txn_FULL_LOAD]
$PMSessionLogFile=$PMRootDir/Logs/AUTO.S_M_F_ACCT_TXN_FULL_LOA.LOG
$DBConnection_EDW=SAS2EDW
 
[s_m_f_acct_txn_daily_a1]
$PMSessionLogFile=$PMRootDir/Logs/SAS_FACT1/WF_FACT1_F.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10,'j')
$$enddate=to_char(sysdate, 'j')
 
[s_m_f_asp_setup]
$PMSessionLogFile=$PMRootDir/Logs/SAS_FACT1/WF_FACT1_F.S_M_F_A.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10,'j')

Modified Text:
[s_m_f_acct_txn]
$PMSessionLogFile=$PMRootDir/Logs/AUTO.S_M_F_ACCT_TXN.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10,'j')
$$enddate=to_char(sysdate, 'j')
 
 
[s_m_f_acct_txn_FULL_LOAD]
$PMSessionLogFile=$PMRootDir/Logs/AUTO.S_M_F_ACCT_TXN_FULL_LOA.LOG
$DBConnection_EDW=SAS2EDW
 
[s_m_f_acct_txn_daily_a1]
$PMSessionLogFile=$PMRootDir/Logs/SAS_FACT1/WF_FACT1_F.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10000,'j')
$$enddate=to_char(sysdate, 'j')
 
[s_m_f_asp_setup]
$PMSessionLogFile=$PMRootDir/Logs/SAS_FACT1/WF_FACT1_F.S_M_F_A.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10,'j')

Thank you.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Hi! Searching for a text string in UNIX

Hi! I'm new here and glad to meet everyone! I've been wrestling with a problem lately however! How do I recursively (recursive means to keep going through the subdirectories until no more are there) search a bunch of textfiles in a long directory structure for a specific string.. but only... (1 Reply)
Discussion started by: skwadim
1 Replies

2. Shell Programming and Scripting

PERL: Searching for a string in a text file problem

Looking for a bit of help. I need to search for a string of words, but unfortunately these words are located on separate lines. for example the text output is: United Chanmpions Ronaldo Liverpool Losers Torres and my script code is print("DEBUG - checking file message"); while... (15 Replies)
Discussion started by: meevagh
15 Replies

3. Shell Programming and Scripting

Searching a particular string with spaces in a data file

Hi, I'm new to shell scripting and require your help in achieving the requirement. I have a data file which stores organization name as one of the column data in a csv data file. Organization name stored in data file is: Canadian OU CAD Sample Data file: 1,5,4,5,, ... (9 Replies)
Discussion started by: andy4013
9 Replies

4. Shell Programming and Scripting

Text data string conversion to Integer

Folks Appreciate your help in understanding issue in relation to below. I need to pul uvalue from a file (tmpfile) and compare it with a number to make decision. Using #!/bin/sh contents of tmpfile : Slot uvalue : 0.16 How I am pulling it: unifval=`awk '/uvalue/ {print $4}' tmpfile` ... (1 Reply)
Discussion started by: wndgs
1 Replies

5. Shell Programming and Scripting

String searching and output to a file in a formatted text

Hi, I'm very new to UNIX scripting and find quite difficult to understand simple UNIX syntax. Really appreciat if somebody could help me to give simple codes for my below problems:- 1) I need to search for a string "TTOH 8031950001" in a files which filename will be "*host*'. For example, the... (3 Replies)
Discussion started by: cuji
3 Replies

6. Shell Programming and Scripting

searching a text string for n'th :

hello, i'm a novice on bsh scripting so thanks for any help here basically i have a shell var $x that looks like this > echo $x nabc1234:!:73394:17155:Gary Mason:/home/garym:/bin/ksh and i'm trying to keep the first 8 characters and the text from the 4th : to the 5th : i've been trying... (9 Replies)
Discussion started by: sasglm
9 Replies

7. Shell Programming and Scripting

find string(s) in text file and nearby data, export to list help

Hi, So I'm kinda new to shell scripts and the like. I've picked up quite a bit of use from browsing the forums here but ran into a new one that I can't seem to find an answer for. I'm looking to parse/find a string AND the next 15 or so charachters that follow the string within a text file... (1 Reply)
Discussion started by: kar23me
1 Replies

8. Shell Programming and Scripting

Need comand or script for append text after searching for the desired string

Hi all, i have a generated report in unix in the following command like input.txt 47.85,10 0124,42.35,8 0125,3.5,2 the input file format is fixed I need the my output file with append text as below output.txt 0124 amount:42.35 0125 amount:3.5 0124 count : 8 0125... (34 Replies)
Discussion started by: hemanthsaikumar
34 Replies

9. Shell Programming and Scripting

How to read all data after a specific string from a text file ?

Hi, I have a file(input.txt) and trying to format as output.txt. See the attached file format. Note: This is a windows file (DOS format) and the commands are also going to execute on windows. Basically I am trying to capture all the data in between Local Group Memberships and Global Group... (10 Replies)
Discussion started by: Monoj2014
10 Replies

10. Shell Programming and Scripting

Modifying text file records, find data in one place in the record and print it elsewhere

Hello, I have some text data that is in the form of multi-line records. Each record ends with the string $$$$ and the next record starts on the next line. RDKit 2D 15 14 0 0 0 0 0 0 0 0999 V2000 5.4596 2.1267 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 ... (5 Replies)
Discussion started by: LMHmedchem
5 Replies
wrjpgcom(1)							   User Commands						       wrjpgcom(1)

NAME
wrjpgcom - insert text comments into a JPEG file SYNOPSIS
wrjpgcom [-replace] [-comment text] [-cfile name] [filename] DESCRIPTION
wrjpgcom reads the named JPEG or JFIF file, or the standard input if no file is named, and generates a new JPEG or JFIF file on the stan- dard output. A comment block is added to the file. The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. Although the standard does not actually define the intended function of COM blocks, they are widely used to hold user-supplied text strings. This enables you to add annotations, titles, index terms, and so on to your JPEG files, and later retrieve the COM blocks as text. COM blocks do not interfere with the image stored in the JPEG file. The maximum size of a COM block is 64K, but you can have many COM blocks in one JPEG file. wrjpgcom adds a COM block, containing text that you provide, to a JPEG file. Ordinarily, the COM block is added after any existing COM blocks, but you can delete the old COM blocks if you wish. OPTIONS
The following options are supported: -cfile name Read the text for a new COM block from the named file. -comment text Supply the text for a new COM block on the command line. -replace Delete any existing COM blocks from the file. OPERANDS
The following operands are supported: filename The name of the JPEG file to which you want to add text comments. EXTENDED DESCRIPTION
To add only one line of comment text, use the -comment option to provide the text on the command line. Specify the comment text within quotes, so that the text is treated as a single argument. Longer comments can be read from a text file. If you specify neither the -comment nor the -cfile option, wrjpgcom reads the comment text from standard input. In such cases, you must supply an input image filename. You can enter multiple lines, up to 64KB. Type an end-of-file indicator, usually Ctrl-D, to terminate the comment text entry. wrjpgcom does not add a COM block if the provided comment string is empty. Therefore, you can use -replace -comment "" to delete all COM blocks from a file. EXAMPLES
Example 1: Adding a Short Comment to in.jpg to Produce out.jpg example% wrjpgcom -c "View of my back yard" in.jpg > out.jpg Example 2: Attaching a Long Comment Previously Stored in comment.txt example% wrjpgcom in.jpg < comment.txt > out.jpg or example% wrjpgcom -cfile comment.txt < in.jpg > out.jpg In this example, 1000 is a number that is larger than the number of rows in the source file. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWjpg | +-----------------------------+-----------------------------+ |Interface stability |External | +-----------------------------+-----------------------------+ SEE ALSO
cjpeg(1), djpeg(1), jpegtran(1), rdjpgcom(1) NOTES
This man page was originally written by the Independent JPEG Group. Updated by Breda McColgan, Sun Microsystems Inc., 2004. SunOS 5.10 26 Mar 2004 wrjpgcom(1)
All times are GMT -4. The time now is 10:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy