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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help substituting text in a file having a single line but no newline char
# 1  
Old 08-27-2010
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.

Code:
$ cat hlq_detail
/outputs/alvan23/PDFs/bills

$ cat hlq_detail | sed 's/alvan23/alvan4/g'

The file hlq_detail does not have a newline char after "bills"
# 2  
Old 08-27-2010
Try it with awk:
Code:
awk 'sub("alvan23","alvan4")' file

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 08-27-2010
Hi.

Out of interest, which OS are you using?

If it's Solaris, try using /usr/xpg4/bin/sed".
# 4  
Old 08-27-2010
Thanks Franklin,

It does work. But, doesn't AWK work in a similar way as SED i.e. it does refer the newline character to check for the end of the line?

---------- Post updated at 03:53 PM ---------- Previous update was at 03:52 PM ----------

I am using HP Unix
# 5  
Old 08-27-2010
OK, thanks Smilie
# 6  
Old 08-28-2010
Code:
exec 6<"myfile"
while read -r LINE<&6
do
  LINE="${LINE/alvan23/alvan4}"
  echo "$LINE"
done > tmp
exec 6<&-
mv tmp myfile

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Deleting newline and making output in single line with spaces

HI I have a file line vi Input 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 (7 Replies)
Discussion started by: Priya Amaresh
7 Replies

3. Shell Programming and Scripting

Formatting File having big single line into 95 Char Per Line

Hi All, I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end. Before:- File Name:- File1.dat 102 121340560... (10 Replies)
Discussion started by: lancesunny
10 Replies

4. UNIX for Dummies Questions & Answers

Append a line to single column text file

I would like to add a line to the end of a single column text file. How do I go about doing that? Input: BEGIN 1 2 3 Output: BEGIN 1 2 3 END Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

Shell to remove a newline char from selected rows in a file.

Greetings! Can we automate the process of removing a newline char from selected rows in a fixed width file using a shell? Input is like abcd1234 xyzd1234 abcd a1b2c3d4 abcd1234 xyzd1234 xx abcd1234 Expected output - abcd1234xyzd1234 abcda1b2c3d4abcd1234xyzd1234 xxabcd1234 ... (3 Replies)
Discussion started by: mailme0205
3 Replies

6. Shell Programming and Scripting

cutting long text by special char around 100 byte and newline

Regard, How can i cut the text by special char(|) around 100 byte and write the other of the text at newline using Perl. ... (3 Replies)
Discussion started by: Shawn, Lee
3 Replies

7. 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

8. Shell Programming and Scripting

Substituting carriage return followed by newline character - HELP

-------------------------------------------------------------------------------- Hi All I have a field being returned from the DB that when opened in Vi shows a ^M before the rest of the field is displayed on the next line. I need it so that the only newline character is the end of the... (14 Replies)
Discussion started by: djkane
14 Replies

9. UNIX for Dummies Questions & Answers

Substituting carriage return follwed by newline character - HELP!

Hi All I have a field being returned from the DB that when opened in Vi shows a ^M before the rest of the field is displayed on the next line. I need it so that the only newline character is the end of the line since I need to transform my file into an Excel report. Thus my idea is to... (1 Reply)
Discussion started by: djkane
1 Replies
Login or Register to Ask a Question