Replace char on text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace char on text file
# 1  
Old 12-11-2010
Replace char on text file

Hi ,

I have problem on replace char on text file

#!/bin/bash

echo "Enter Third value : "
read a


sed '2 s/192.160.1.1/cut -d"." -f3/$a/g' tcpip.txt > a.txt


I want replace line 2 on tcpip.txt with value a that I input but it's not run

Please help me
# 2  
Old 12-11-2010
Search for 192.160.1.1 on line 2 of tcpip.txt, and replace 3rd value with contents of a:

Code:
sed "2 s/192.160.1.1/192.160.$a.1/" tcpip.txt > a.txt

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 12-11-2010
Thanks for your answer, it running well .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Replace \n char in Data

File is pipe delimited with 17 fields. We may get \n char (1 or more \n in one field or multi fileds) in data in any field. Need to replace \n in data with space and not the Ture \n that is line separator. I tried below awk command it did not work as expected. awk '(NR-1)%2{$1=$1}1' RS=\|... (9 Replies)
Discussion started by: rajeshkumare
9 Replies

2. UNIX for Beginners Questions & Answers

Views How to replace a CRLF char from a variable length file in the middle of a string in UNIX?

My sample file is variable length, with out any field delimiters. It has min of 18 chars length and the 'CRLF' is potentially between 12-14 chars. How do I replace this with a space? I still want to keep end of record, but just want to remove these new lines chars in the middle of the data. ... (7 Replies)
Discussion started by: chandrath
7 Replies

3. UNIX for Dummies Questions & Answers

Replace the unexpected newline char with space in a Fixed width file

Input eg: Ouput Expected. The #rd line had the unexpted new line, which need to be replaced with space. I was planing to go with checking the length of each line using awk and if the length is less than the defeined limit, (12 in above case) will replace the newline with space. ... (5 Replies)
Discussion started by: deepakwins
5 Replies

4. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

5. Shell Programming and Scripting

Replace char between chars - help needed

Hello, I have a csv file with "^" as text delimiters and "|" as field delimiters. It's converted from a xls file. One record looks like this: ^Tablete Internet^|Archos|501838|^Tableta Internet ARCHOS 80 G9 ...| ... (more lines) ... "501|838"^|330.00|USD|sl|12|0|Link|^router wireless 150... (10 Replies)
Discussion started by: go0ogl3
10 Replies

6. Shell Programming and Scripting

Find and replace all extended char.

Hi Guys, I wand find and replace all Extended ASCII Codes from all my log files. My Log files: /home/Kalr/PPool/Output i have logs file in sub dir. /home/Kalr/PPool/Output/X /home/Kalr/PPool/Output/Y /home/Kalr/PPool/Output/Z My Abc.log file input: Extended ASCII Codes :– ... (4 Replies)
Discussion started by: asavaliya
4 Replies

7. Shell Programming and Scripting

Help substituting text in a file having a single line but no newline char

Hello, Need help substituting a particular word in a file having a single line but no newline character at the end. I was trying to use sed but it doesn't work probably because there is no newline char at the end of the line. $ cat hlq_detail /outputs/alvan23/PDFs/bills $ cat... (5 Replies)
Discussion started by: Shan_u2005
5 Replies

8. Shell Programming and Scripting

How to replace text in a file with text entered

I am trying to write a shell script that will allow the typing of a value, then using that value to replace data in a text file. I suspect I need sed. The format of the file is: Variable1:Value1 Variable2:Value2 The interaction would be something like: Shell Prompt: "Please enter the... (9 Replies)
Discussion started by: cleanden
9 Replies

9. Shell Programming and Scripting

How to replace any char with newline char.

Hi, How to replace any character in a file with a newline character using sed .. Ex: To replace ',' with newline Input: abcd,efgh,ijkl,mnop Output: abcd efgh ijkl mnop Thnx in advance. Regards, Sasidhar (5 Replies)
Discussion started by: mightysam
5 Replies

10. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies
Login or Register to Ask a Question