Sponsored Content
Top Forums Shell Programming and Scripting How do I insert text with sed ? Post 302776407 by Paul Walker on Wednesday 6th of March 2013 09:17:16 AM
Old 03-06-2013
How do I insert text with sed ?

Maybe I should expailed myself more thoroughly. What I am trying to do is pick up a string of text from the begining of the line, an example of the string is this: "05-03-2013-08-59-16", this string is actualy a time stamp, that is associated with a number of file names that appear later on in the same line. The file names all end the same way, that is with a ".pdf_.html" I need to insert the string from the beginning of the line between the ".pdf_" and the ".html" everytime there is an occurance of ".pdf_.html"
Here is an example of the original text file:
Code:
<textarea name="file_links" value='05-03-2013-08-59-16 http://216.234.35.180/SCL_Preflight_Report_Page/1 small_format_stores_sign_tyr_5xpoints_22x28.pdf_.html http://216.234.35.180/SCL_Preflight_Report_Page/2 898611_Ped_Markham Reno_FINAL.pdf_.html'

And the following is the way I need it to look:
Code:
<textarea name="file_links" value='05-03-2013-08-59-16 http://216.234.35.180/SCL_Preflight_Report_Page/1 small_format_stores_sign_tyr_5xpoints_22x28.pdf_05-03-2013-08-59-16.html http://216.234.35.180/SCL_Preflight_Report_Page/2 898611_Ped_Markham Reno_FINAL.pdf_05-03-2013-08-59-16.html'

Also string that represents the time stamp will never be constant except for the format of numbers and dashes, and I need to perform the same operation on a number of files with changing time stamps and filenames.
The only constant will be the format of the timestamp and the position of the string: ".pdf_.html" at the end of the file names
thanks very much for all your help
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Insert Text With Sed

Hello. Trying to insert text at line 1 and after last line of file. I have searched posts but nothing seems to work. I keep getting extra characters error or nothing gets inserted into the file. #!/bin/sh touch textfile.txt sed 'i\ Add this line before every line with WORD' textfile.txt ... (5 Replies)
Discussion started by: steveramsey
5 Replies

2. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

3. Shell Programming and Scripting

sed insert text at particular line

I know that sed -n '12p' file will print line 12 but how might I insert text to a specified line? thanks (2 Replies)
Discussion started by: action_owl
2 Replies

4. Shell Programming and Scripting

Insert text with Sed (in various positions)

Hello. I'm trying to insert text in various positions and I could only do that using pipes for each position. Example: cat file | sed -e 's#\(.\{5\}\)\(.*\)#\1:\2#g' | sed -e 's#\(.\{26\}\)\(.*\)#\1:\2#g' Insert ":" at position 5 and 26. it can be done in the same sentence, without using... (4 Replies)
Discussion started by: </kida>
4 Replies

5. Shell Programming and Scripting

sed insert text without newline

Hi, I use sed to insert text at beginning of a file. But sed inserts a newline after my text that I do not need. For example, I want to insert "foo" at the beginning of my file: > cat myfile This is first line. > sed -i '1i\foo' myfile > cat myfile foo This is first line. ... (5 Replies)
Discussion started by: tdw
5 Replies

6. Shell Programming and Scripting

Using sed to insert text file at first line

sed '1r file.txt' <source.txt >desti.txt This example will insert 'file.txt' between line 1 and 2 of source.txt. sed '0r file.txt' <source.txt >desti.txt gives an error message. Does anyone know how 'sed' can insert 'file.txt' before the first line of source.txt? (18 Replies)
Discussion started by: psve
18 Replies

7. Shell Programming and Scripting

sed to insert a slash and keep text

I have: /path/to/my/fixdir/MD1234567.tar I want to have: /path/to/my/fixdir/MD/1234567.tar fixdir never changes but MD does and how many numerical digits does. I want something like: /usr/bin/sed 's/fixdir\/../fixdir\/..\//' This ends up: /path/to/my/fixdir/../1234567.tar But... (3 Replies)
Discussion started by: crowman
3 Replies

8. Shell Programming and Scripting

Insert text using sed

sed 's/$/TEST/g' will insert TEST at the end of each line. i want to insert TEST at column 64 (7 Replies)
Discussion started by: lawsongeek
7 Replies

9. Shell Programming and Scripting

sed insert text 2 lines above pattern

Hi I am trying to insert a block of text 2 lines above a pattern match using sed eg #Start of file entry { } #End of file entry new bit of text has to be put in just above the } eg #Start of file entry { New bit of text } #End of file entry (7 Replies)
Discussion started by: eeisken
7 Replies

10. Shell Programming and Scripting

Using sed to insert text between lines

Hello, I am trying to insert a section of text between lines in another text file. The new lines to be inserted are: abcd.efgh.zzzz=blah abcd.efgh.xxxx=blah Where N = 0 to 2 Original File: abcd.efgh.wwxx=aaaaa abcd.efgh.yyzz=bbbbb abcd.efgh.wwxx=aaaaa abcd.efgh.yyzz=bbbbb... (3 Replies)
Discussion started by: tsu3000
3 Replies
STPNCPY(3P)						     POSIX Programmer's Manual						       STPNCPY(3P)

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
stpncpy -- copy fixed length string, returning a pointer to the array end SYNOPSIS
#include <string.h> char *stpncpy(char *restrict s1, const char *restrict s2, size_t size); DESCRIPTION
Refer to strncpy(). COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2013 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, Copyright (C) 2013 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. (This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Stan- dard is the referee document. The original Standard can be obtained online at http://www.unix.org/online.html . Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html . IEEE
/The Open Group 2013 STPNCPY(3P)
All times are GMT -4. The time now is 04:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy