Add string into certain lines - sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add string into certain lines - sed
# 1  
Old 01-15-2018
Add string into certain lines - sed

Hello all,

I have surely an easy question - but at the moment I do not see the solution.

All what I want is to add the string "/9201" within a file when a line starts with ":47A:".

This is how a file look like:

Code:
Information Tool
 :12:Delimiter
 :3:Space
 :47A:0329
 :3:Space

After the Substitution it should look like:

Code:
Information Tool
 :12:Delimiter
 :3:Space
 :47A:0329/9201
 :3:Space

What I tried so far is:
Code:
sed 's/\(^:47A.*\)/\1\/9201/g' <file>

Tx for your help.
# 2  
Old 01-15-2018
Code:
sed '/^ *:47A/s/$/\/9201/' infile

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 01-15-2018
@rdrtx1: When I will do it in this way I will get the same result as with my command:

Code:
Information Tool
 :12:Delimiter
 :3:Space
/92010329
 :3:Space

By the way - there is no space before the ":". That is the code-tag... :-(

---------- Post updated at 05:31 PM ---------- Previous update was at 05:03 PM ----------

@rdrtx1: I did another Trial. I copied the Content of the file into another file and did the next Trial on this new file.
And now it works. The reason is: there is something wrong with my original file. I will have a look into the hex structure.
So, thanks for your help - nevertheless.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for 2 string in 2 lines with sed ?

Hi ! I want to search a string in all lines with sed. If that string is there, i want to look for an other string in the next line.If that string is there i want to put an other line under it. eg: aaa bbb ccc ddd cat bla.txt | sed -e '/aaa/a\' -e ' \!!!' in the upper case, i would... (6 Replies)
Discussion started by: fugitivus
6 Replies

2. Shell Programming and Scripting

Grep and sed (replace string in patterned lines)

Grep and Sed (replace string in patterned lines) Hi all, I want to grep for "PATTERN" and only if "PATTERN" is in a line, this line shall be used as replacement input e.g. for SED. I don't get it running in one line. NOT RUNNING - just first idea... I don't know how to redirect grep... (2 Replies)
Discussion started by: unknown7
2 Replies

3. Shell Programming and Scripting

Add string number to lines

So I have a file in the form > akdfvcnciejcndmdjfk > kdjkkkifjeeeeelfjfuf > fjfhchdejhfhfhfhfhfhf > skdkdhfhvnvncnccm and I would like it to come out in the form >1 akdfvcnciejcndmdjfk >2 kdjkkkifjeeeeelfjfuf >3 fjfhchdejhfhfhfhfhfhf (3 Replies)
Discussion started by: viored
3 Replies

4. Shell Programming and Scripting

Awk, sed - concatenate lines starting with string

I have a file that looks like this: John Smith http://www.profile1.com http://www.profile2.com http://www.profile3.com Marc Olsen http://www.profile4.com http://www.profile5.com http://www.profile6.com http://www.profile7.com Lynne Doe http://www.profile8.com http://www.profile9.com... (3 Replies)
Discussion started by: locoroco
3 Replies

5. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

6. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

7. Shell Programming and Scripting

Add two lines in a single string

Dear All, I want to add two lines in single string. Example: String1: God Bless You. String2: Thank You. Now i want to store these two above lines into a single string(str) and when i will echo it, it should be like > echo $str God Bless You. Thank You. Please help me. Thanks in... (1 Reply)
Discussion started by: umesh.rout
1 Replies

8. Shell Programming and Scripting

Like grep -v for a string over 2 lines? Sed?

Hi, I have a log file that I need to monitor as it's being written to, and I want to exclude certain strings from the output. At the moment I'm using ... tail -f LogFileName_`date +%d`.log | egrep -v "First String To Exclude | 2nd string | 3rd string" ...which works OK - but now I need to... (1 Reply)
Discussion started by: jake657
1 Replies

9. Shell Programming and Scripting

using sed command to delete a string spanning multiple lines

file1 contains the following data sssssssssss firstline secondline pppppppppp ssssssssss Using sed comamnd i am trying to delete firtsline secondline. so, output should be sssssssssss pppppppppp ssssssssss I tried in the following the way, but it is not working. sed ... (9 Replies)
Discussion started by: radha.kalivar
9 Replies

10. UNIX for Dummies Questions & Answers

Delete multiple lines containting a variable string using SED.

Good morning, Novice scripter in Unix here, and I've run into and sed task I can't quite wrap my head around. I'm pulling my hair out fast enough as it is and thought I would go to the knowledge bank. I have a sorted file that I'm trying to trim down by deleting any line whose first few... (2 Replies)
Discussion started by: selkirk
2 Replies
Login or Register to Ask a Question