sed - appending text


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed - appending text
# 1  
Old 05-06-2011
sed - appending text

Hey all

I am trying to append a file called datebook.txt. I want to append the end of each line containing the name Fred with three ***. I believe I need to make the * loose its meta character meaning in addition to using the append command. I have tried several variations of this command and I cant seem to get it right. I am new to all this and can't seem to get it to work. Any help would be greatly appreciated. Thanks, citizencro
sed '-e/fred/a//***/' <datebook.txt >datebook.sh
# 2  
Old 05-06-2011
Quote:
Originally Posted by citizencro
sed '-e/fred/a//***/' <datebook.txt >datebook.sh
Doesn't seem right, the man page for 'sed' states that the option -e adds a script to the command(s), and hence should be a [space] after -e .

I also think you may need to escape each '*' with a backslash (\), like so: 's//\*\*\*/'

Post your command line input as well as your exact output in code tags.
# 3  
Old 05-06-2011
Hi, citizencro:

If you are simply trying to add to the end of a line, use the substitute command (s) with a regular expression that matches nothing but the end of line ($).

The append command (a) will create an entirely new line.


Quote:
Originally Posted by AlphaLexman
I also think you may need to escape each '*' with a backslash (\), like so: 's//\*\*\*/'
The * is not special in the replacement text. \* results in an undefined sequence.

Regards,
Alister
# 4  
Old 05-06-2011
@ Alister: Thanks for the correction.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending a text to the top of each line

Platform : Oracle Linux 6.8 Shell : bash I have a file which has lines like below. These are SELECT queries (SQL) In each line, I want the word just after FROM keyword to be copied and printed on the top along with the word PROMPT. The words after FROM clause below are table names. So, they... (6 Replies)
Discussion started by: John K
6 Replies

2. Shell Programming and Scripting

Sed command help (appending)

I need to append a user to the end of a group in the /etc/group file ftp::49:user1,user2... what I want to to add a new user to the group file so that I won't have to open it up and append manually and I can't user "usermod" it fails this user will be coming from a variable (11 Replies)
Discussion started by: slufoot80
11 Replies

3. Shell Programming and Scripting

appending text to a file

I am trying to count number of record in a file and then append a trailer to that file. Trailer should e in the format as below T| <count of records> count of records ---> this count should be one less than the actual count obtained, as the file will have a header. I have drafted a... (3 Replies)
Discussion started by: siteregsam
3 Replies

4. Shell Programming and Scripting

sed appending problem

i have a number of java files containing eg: --------------myfile.java-------------- package zip.fun.myfiles; import java.* import something..; import sdfdfdsa; ... ... -------------------------------------------- Now I need to append / insert a line as follows: ... (10 Replies)
Discussion started by: linuxadmin
10 Replies

5. UNIX for Dummies Questions & Answers

Appending two text files

Hi, i am using unix server and bash shell.. i have two csv files... i have file 1 as below... arun bvb ssx ccc and file 2 as below manas friu dfgg cat (3 Replies)
Discussion started by: arunmanas
3 Replies

6. Shell Programming and Scripting

Appending text to a file

Hi, Want to append the text to a new file, echo "set `sqlplus -S abc/xyz123@localdb<<EOS" >> chk_test_append.sh echo "EOS`" >> chk_test_append.shbut getting the below error : what wrong is written ? With Regards (4 Replies)
Discussion started by: milink
4 Replies

7. UNIX for Dummies Questions & Answers

appending text on top of another file

Dear All, I have two files One is script file in which I am writing commands to append a text in a normal file. I want to insert the text on top of the file. I dont want to use sed and awk commands nor temp file. is it possible? (3 Replies)
Discussion started by: anjali
3 Replies

8. Shell Programming and Scripting

Appending text of one file into other

hello, I am trying to append\insert the text that exists in file A into file B. for instance: File A contains: abcdef File B contains: ghijklm can i insert into file A the content in file B without damaging\deleting the input into file A? is there a command in shell that enables such... (1 Reply)
Discussion started by: danland
1 Replies

9. Shell Programming and Scripting

appending and sed

Hello, I want to add string #REAL at the end of all lines that contain real numbers. How to do this using sed ? (1 Reply)
Discussion started by: scotty_123
1 Replies
Login or Register to Ask a Question