PS1 (Prompt character) appearing in cat output | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

PS1 (Prompt character) appearing in cat output

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-14-2013
omega3 omega3 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 23 August 2014, 4:56 AM EDT
Posts: 29
Thanks: 29
Thanked 1 Time in 1 Post
PS1 (Prompt character) appearing in cat output

RedHat Linux 5.8/Korn Shell

I have text file name /etc/oracle/config.loc. It has the following text

Code:
#Device/file  getting replaced by device +OCR
ocrconfig_loc=+DATA
ocrmirrorconfig_loc=+OCR

But , when I open this file using cat , the PS1 character (for prompt) appears as the last character in the last line


Code:
$ PS1='> '
>
> cat /etc/oracle/config.loc
#Device/file  getting replaced by device +OCR
ocrconfig_loc=+DATA
ocrmirrorconfig_loc=+OCR
local_only=false>

Changing PS1 to $ sign. As you can see below the dollar sign appears in cat output in the last line


Code:
> PS1='$ '
$
$
$ cat /etc/oracle/config.loc
#Device/file  getting replaced by device +OCR
ocrconfig_loc=+DATA
ocrmirrorconfig_loc=+OCR
local_only=false$

But it doesn't happen for all files. For instance, PS1 character doesn't appear in the below file abc.txt

Code:
$ cat abc.txt
hello world

Why is this happening ? How can I fix this ?
Sponsored Links
    #2  
Old 06-14-2013
hergp hergp is offline Forum Advisor  
Problem Eliminator
 
Join Date: Jan 2010
Last Activity: 23 October 2014, 10:21 AM EDT
Location: Vienna, Austria
Posts: 802
Thanks: 18
Thanked 168 Times in 150 Posts
It seems, your file /etc/oracle/config.loc does not end with a newline character.

Opening and saving the file with a text editor, like vi, should correct this issue.
The Following User Says Thank You to hergp For This Useful Post:
omega3 (06-14-2013)
Sponsored Links
    #3  
Old 06-14-2013
omega3 omega3 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 23 August 2014, 4:56 AM EDT
Posts: 29
Thanks: 29
Thanked 1 Time in 1 Post
Cool. I opened the file in vi and saved it. The character has disappeared.
THANK YOU hergp for 'eliminating this problem'.
Does this imply that VI has inserted a newline character at the end ? What could have caused the original issue ? The original file was created by Oracle's Clusterware.

I have kept a backup of the original file for future analysis.
    #4  
Old 06-14-2013
hergp hergp is offline Forum Advisor  
Problem Eliminator
 
Join Date: Jan 2010
Last Activity: 23 October 2014, 10:21 AM EDT
Location: Vienna, Austria
Posts: 802
Thanks: 18
Thanked 168 Times in 150 Posts
You are right, that vi wrote a newline at the end of the file. That's what most editors do.

The cause is probably, that clusterware does not mind or care about the terminating newline.

You can easily create such a file on your own. Just write


Code:
$ printf "this is a line without newline" >testfile
$ cat testfile
this is a line without newline$

BTW: keeping a backup is always a good idea
The Following User Says Thank You to hergp For This Useful Post:
omega3 (06-14-2013)
Sponsored Links
    #5  
Old 06-14-2013
omega3 omega3 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 23 August 2014, 4:56 AM EDT
Posts: 29
Thanks: 29
Thanked 1 Time in 1 Post
Thank you hergp.
If clusterware used echo command as shown below , then there wouldn't have been any problem


Code:
$ echo "blueSkies" > hello.txt
$
$ cat hello.txt
blueSkies

By the way , how can I make the new lines visible ? Is there a command to see new lines (\n) and other special characters ?
Sponsored Links
    #6  
Old 06-14-2013
wisecracker's Avatar
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 23 October 2014, 3:18 PM EDT
Location: Loughborough
Posts: 642
Thanks: 133
Thanked 136 Times in 113 Posts
A simple test:-

This one has the newline inserted...


Code:
echo "Hello World!"<CR>

This one doesn't...


Code:
printf "Hello World!"<CR>

Sponsored Links
    #7  
Old 06-14-2013
hergp hergp is offline Forum Advisor  
Problem Eliminator
 
Join Date: Jan 2010
Last Activity: 23 October 2014, 10:21 AM EDT
Location: Vienna, Austria
Posts: 802
Thanks: 18
Thanked 168 Times in 150 Posts
Quote:
Originally Posted by omega3 View Post
By the way , how can I make the new lines visible ? Is there a command to see new lines (\n) and other special characters ?
Try

Code:
od -c filename

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Why is my PS1 breaking my prompt? treesloth UNIX for Dummies Questions & Answers 2 05-31-2013 04:35 PM
How to get a Prompt (PS1) Timestamp under /sbin/sh? Solarius Shell Programming and Scripting 1 09-13-2010 11:09 PM
PS1 prompt venhart UNIX for Dummies Questions & Answers 4 08-01-2008 02:26 AM
colors in Prompt - $PS1 rakeshou UNIX for Dummies Questions & Answers 3 12-17-2007 02:07 PM
echoed prompt not appearing until after read command. simonb Shell Programming and Scripting 2 03-19-2006 10:15 AM



All times are GMT -4. The time now is 08:39 AM.