Need to log the sed command used to replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to log the sed command used to replace
# 1  
Old 05-04-2016
Need to log the sed command used to replace

In a shell script I am replacing the asterisks in a file:

Code:
sed "s/\*/"0"/g" /home/download/$COMPANY_CODE/file_new > /home/download/$COMPANY_CODE/file

I need to log which positions were replaced & position(01:20) from the line it was replaced in. I am not sure how to do so. Also, instead of replacing all of the asterisks in a file, how can I just replace the asterisks in the file of the columns I am sure need replaced:
position(1050:1059) & position(1249:1258)
And still log it?
# 2  
Old 05-04-2016
Are the character positions in the file you are processing numbered with the 1st character on a line being position 0 or position 1?

How big is your input file (/home/download/$COMPANY_CODE/file_new)?

What operating system are you using?

What shell (including release/version number) are you using?

Please show us (or attach) a few sample input lines and the exact output(s) you want to produce from that input.
# 3  
Old 05-04-2016
The first position used is 01.
File is 22,000 KB.

Code:
AIX server 1 6 00F7E54B4C00
  
      PID    TTY STAT  TIME COMMAND
 19399110 pts/53 A     0:00 -sh

the lines will contain characters, numbers, spaces all through position 1444. Occasionally position(1050:1059) & position(1249:1258) will contain asterisks "**********". I want to convert those to zeros "0000000000". I don't want to convert any other asterisks that may be in the file. These cause issues due to a sql loader trying to insert them into Oracle tables on a numeric field.

I cannot attach actual data.

Last edited by Don Cragun; 05-04-2016 at 04:39 PM.. Reason: Add CODE tags.
# 4  
Old 05-04-2016
Sample input lines do not need to be actual data; they just need to provide representative data.

Are these text files (no null bytes and a <newline> character at the end of each line) or are they binary files (may contain null bytes, for example in floating point numeric constants, and record length is determined by byte count only instead of containing a line terminating character sequence)?

What codeset is used to encode data in these files? (Perhaps ASCII, ISO-8859-1, UTF-8, or EBCDIC?)

In your 1st post in this thread, you said:
Quote:
And still log it?
If you want a log (in addition to an output file that is a modified version of the input file), exactly what do you want logged? Please show us a sample of what a log should look like for a particular set of representative sample input records.

Please help us help you. Don't make us guess at everything that will determine what tools can be used to process your data to get the results you want! Making us guess at everything wastes the time of anyone who wants to help you, is likely to get you suggestions that don't stand a chance of working with your real data, and makes it much less likely that you will get any suggestions that work in your environment.
# 5  
Old 05-05-2016
I have attached a sample document. I believe it is ASCII. I've attached it as txt but it is a dat file written in pervasive psql. Best way to view the file is with Ultra Edit.
I need to replace the "**********" with "0000000000" but only when it occurs in position(1050:1059) & position(1249:1258). The other asterisks can stay in the file. After replacing the asterisks this file gets loaded in to Oracle. I need to write to a log the position(01:20) from the line it was replaced in. So in this sample line 13 position 1249:1258 will get replaced. After replacing the asterisks, it needs to write "2y102330" to a log file. The shell script the replace command will be contained in is already creating a log file so maybe just an echo command to show which customers were updated. Echo "position(01:20)" output = "2y102330". I am not sure though.
# 6  
Old 05-05-2016
OK. So to be clear, you have a sample input file containing 1,587 lines each containing 1,602 bytes with DOS (<CR><NL>) line terminators and one incomplete line of 1,600 bytes with no line terminator. By definition, as you said, that is not a text file.

Can the modified output from your SAMPLE.txt input file be a real text file, or does the output have to have the same unterminated, trailing partial line?

Does the output file have to use DOS line terminators, or can we change them to UNIX (<NL>) line terminators?

Are you really unable to specify the format of the output you want to produce for the log file that records fields that were changed from containing ********** to containing 0000000000?
# 7  
Old 05-06-2016
The last line should be complete & include a line terminator. The actual file to be updated is ~ 14,087 lines depending on the number of customers. The output file can be the same format as the input. The output file just gets loaded into Oracle using SQL LOADER. For the output I do want the reference of position(01:20) from each line changed. Thanks for your assistance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed Command to replace particular value.

Hi , My input file contain : list = 3 14 15 10 9 11 12 18 19 20 21 22 23 24 25 26 6 1 2 3 4 5 7 8 16 17 27 28 30 29 Expected output : list = 0 0 0 0 0 0 0 18 0 20 0 0 0 0 0 0 6 0 0 3 4 0 0 0 0 0 0 0 0 0 I want to keep the 8,10,16,17,22 value from the list and put 0 on rest of the... (9 Replies)
Discussion started by: Preeti Chandra
9 Replies

2. Shell Programming and Scripting

sed replace command

Hi. I need to append/prefix an & character to every 'single' & character (not when there are 2 or more grouped together) I find in a file. I can do it using this cmd: cat ${file} | sed -e 's/&/&&/g' > ${new_file} How can I modify this to ensure I only replace single &'s and not operate... (11 Replies)
Discussion started by: user052009
11 Replies

3. Shell Programming and Scripting

Find and replace using sed command

The content of the file filea.txt is as follows. --------- case $HOSTNAME in aaa) DS_PARM_VALUE_SET=vsDev APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt ;; bbb) DS_PARM_VALUE_SET=vsQA... (3 Replies)
Discussion started by: kmanivan82
3 Replies

4. Shell Programming and Scripting

sed command to find and replace

Hello All, I need a sed command to find and replace below text in multiple files in a directory. Original Text :- "$SCRIPT_PATH/files" Replace with :- "$RESOURCE_FILE" Thank you in advance !!! Regards, Anand Shah (1 Reply)
Discussion started by: anand.shah
1 Replies

5. Shell Programming and Scripting

search and replace with sed command

hi, suggest me in the below script.. if In above I wanna replace "" with "]". (2 Replies)
Discussion started by: divya bandipotu
2 Replies

6. Shell Programming and Scripting

sed command to replace a character at last

Hi All, I have a file having one line only. It is like trapsess:inform|10.232.167.18|1|1|50|25|0|0|0|5|1|1|78|0037| I want to replace the numbers in last two columns by As. It should look like trapsess:inform|10.232.167.18|1|1|50|25|0|0|0|5|1|1|AA|AAAA| Please, suggest me any shell... (12 Replies)
Discussion started by: mukeshbaranwal
12 Replies

7. Shell Programming and Scripting

Replace with a variable in sed command

Hello, I have this command and it works fine. My question is that how can we replace the N by a variable, to print for instance a big number of lines. It means if I want 100 lines after an expression, to not put "N" 100 times in the sed. Code: $ sed -n '/aaa/{n;N;N;s///g;s/;/; /g;p;}'... (2 Replies)
Discussion started by: rany1
2 Replies

8. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

9. UNIX for Dummies Questions & Answers

SED command to search for numeric and replace

Hi I am very new to linux and scripting. I need to replace numbers abc with number xyz inputting from a reference file. I used the following command - sed "s/$grd/$lab/" , where $grd and $lab comes from reference file. The problem is the above line doesnt take care of space..... (1 Reply)
Discussion started by: ajayh
1 Replies

10. Shell Programming and Scripting

sed search and replace command

Hi, I would like to seek help on how i can arrive on this result. sample.txt: product_code IN (param001) and product_type IN (param004) product_code IN (param002) and product_type IN (param005) product_code IN (param003) and product_type IN (param006) I would like to change the param001... (1 Reply)
Discussion started by: janzper
1 Replies
Login or Register to Ask a Question