Append text error?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append text error?
# 1  
Old 07-26-2011
Append text error?

Sup guys, today I tried to append a string from my text by asking the user to input and change the specific text they wanna append.
The problem is that, the code looks logically correct, but when I run it there's an error somewhere.
Can anyone identify for me?

Code:
echo "Search data"
read current
echo "Data to be changed"
read change
sed "/$current/$change" file.txt > file1.txt && mv file1.txt file.txt

My file.txt contains the following.

sampleA:Alex:30:10:10
sampleB1:Tracy:2.56:8:4
sampleZ5Smiliearryl:3:50:7

It gives me an error.
sed: -e expression #1, char 8: extra characters after command.

So let's say I want to change Alex name to Bryan is this the way to do it?
# 2  
Old 07-26-2011
I have not had lunch yet, but I am guessing that you are not telling sed what to do. Perhaps (note the s)

Code:
sed "s/$current/$change" file.txt > file1.txt

This User Gave Thanks to joeyg For This Post:
# 3  
Old 07-26-2011
Sorry for the trouble man but I would like to keep the same file(file.txt) instead of saving it to a new file(file1.txt) so thats why I got the && mv command.
# 4  
Old 07-26-2011
Your problem is still with the "sed":
Code:
sed "s/$current/$change/g" ...

These 2 Users Gave Thanks to Shell_Life For This Post:
# 5  
Old 07-26-2011
Ahh it work perfectly thx!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to preserve the same text and modify the same text to append?

Hi, I have an issue modifying a file. Below is the content of the file. File name - a.txt SELECT LISTAGG(SCORE), LISTAGG(VB), LISTAGG(SCORE*12 + 3), LISTAGG(DOB) from T_CONCAT ; SELECT LISTAGG(SCORE), LISTAGG(VB), LISTAGG(SCORE*100 + 3), from... (1 Reply)
Discussion started by: Mannu2525
1 Replies

2. Shell Programming and Scripting

How to append a text file?

i have to append a text file grep for a word, if found, put comment in starting of the line. here is an example cat test.sh bin/ksh Hello World Test Message :wq! search for "bin" word in test.sh file if found comment it out at starting of the line: Output as follows: #bin/ksh... (5 Replies)
Discussion started by: raghur77
5 Replies

3. Shell Programming and Scripting

Use sed to append text to filenames if text not already present

I have some html with hrefs that contain local links to pdf filenames. These filenames should have standardised names, i.e. there should be a label prior to the ".pdf" filename suffix. There can be many of these links on a single line of text and some may already have the label. For example ... (13 Replies)
Discussion started by: adb
13 Replies

4. UNIX for Dummies Questions & Answers

Append text to files with a same pattern

Hi Folks, I wanted to know if i can use RegEx in a for-loop of a shell script. Here's a scenario, I have a set of files say x1, x2, x3..x9 in a directory(obviously with files other than this pattern). I want to append a line of text to all files that follow pattern x. Can someone help me out? I... (4 Replies)
Discussion started by: prithvirao17
4 Replies

5. Shell Programming and Scripting

Trying to search for a string and append text only once

Hi I am trying to search for a particular occurrence of a string in a file, and if found, append another string to the end of that line. Here is my file contents: column1 userlist default nowrite=3 output=4 column2 access default nowrite=3 Here is the code: A="user=1... (1 Reply)
Discussion started by: bludhemn
1 Replies

6. Shell Programming and Scripting

Copy & Append text

Hi, I have a huge text file that contains contents like below. echo 2VPMUM1CMP01_2011-05-10_18_CPU_Stats_1.txt awk -F, '{sub ("%","",$8);sum+=100-$8;if (100-$8>max){max=100-$8}}END{printf "max=%.1f%\navg=%.1f%\n",max,sum/NR}' echo 2VPMUM1CMP01_2011-05-11_10_CPU_Stats_1.txt awk -F,... (2 Replies)
Discussion started by: SunilB2011
2 Replies

7. Shell Programming and Scripting

append each line with text

hi, I've a file with some text in it, i need to append few strings in the beginning and end of each row. --in file richie matt .. --out file hi, 'richie' is here hi, 'matt' is here ... I tried with awk command, but it fails because of ' Thanks (2 Replies)
Discussion started by: dvah
2 Replies

8. Shell Programming and Scripting

Cut and append the text

I have a text like this ... i need append the text whihc is after 'csb' into the end of the line input ----- sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl sdir;csp oc_lib-0.10.4;bdir;cbpdob ---enable-useosstl output sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl... (6 Replies)
Discussion started by: girija
6 Replies

9. Shell Programming and Scripting

how to append text into a file.

I have a command stream that will parse down an ftp DIR listing of a remote directory and return the name of the newest file that I am interested in. The command is sed -e '/^d/d' sppay.listing |sed -n -e '/SPPAY/p'|sort -r -k 43M,45 -k 47,48 -k 50,54|sed -n -e '1p'|cut -c 56-99 and what it... (2 Replies)
Discussion started by: beilstwh
2 Replies

10. Shell Programming and Scripting

Text Append

I'm creating a script that counts the number of users currently online, then records that in a file called "log.txt" along with the time. Everytime the script is ran, the script appends the "log.txt" this is what I have: who|wc|cut -c6,7>>log.txt date|cut -c12-24>>log.txt After running... (5 Replies)
Discussion started by: 801238429
5 Replies
Login or Register to Ask a Question