How to strip '$' sign on the line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to strip '$' sign on the line
# 1  
Old 03-30-2011
How to strip '$' sign on the line

echo "dddd$dddd"|sed 's/$//' will return dddd
echo "dddd$ddd"|tr -d '$' will return dddd

I need to replace it with any other character or just live a blank space instead

Thank you!

Last edited by Franklin52; 03-31-2011 at 06:39 AM.. Reason: Code tags
# 2  
Old 03-30-2011
Code:
$ echo 'dddd$dddd'| ruby -e 'print gets.split("$").join(" ")'
dddd dddd

# 3  
Old 03-30-2011
Thanks for the prompt reply. Though I need to use ksh commands. (sorry for omitting that)
# 4  
Old 03-30-2011
because when you echo it, you don't get the full chars.

Code:
$ echo "dddd$dddd"
dddd

try this:
Code:
$ echo "dddd\$dddd"|sed 's/\$//'
dddddddd

# 5  
Old 03-30-2011
this obviously works but I unable to put \ in front of $ as the string generated by others.

---------- Post updated at 12:04 PM ---------- Previous update was at 12:02 PM ----------

also I probably could have used awk to spilt it by $ and rejoin it but I don't know how many of them could be there. No I can't. As you noticed it just does not read beyond the $ so ...

Last edited by zam; 03-30-2011 at 10:41 PM..
# 6  
Old 03-30-2011
Quote:
Originally Posted by zam
echo "dddd$dddd"|sed 's/$//' will return dddd
echo "dddd$ddd"|tr -d '$' will return dddd

I need to replace it with any other character or just live a blank space instead

Thank you!
Problem is shell is replacing $ddd with contents of ENV var ddd before string even gets to sed (or awk):

Code:
$ ddd=OOps!
$ echo "dddd$ddd"
ddddOOps!
$ echo 'dddd$ddd'
dddd$ddd

# 7  
Old 03-30-2011
Thanks Smilie I get it ! . But it does make life easy as I have no idea what will be placed after $. It will be different all the time
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - How to replace right part of equal sign (=) on a line

Hello. Using a bash script , I have a variable name for the file I want to modify FILE_TO_EDIT="/etc/my_config_file"And I have a variable name for the parameter to change PARAMETER="fallback_node" PARAMETER_NEW_VALUE="http://my_server_name.com/new_path" A config file may contain : 1°)... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Shell Programming and Scripting

Moving line up if line starts with + sign.

Hello everyone, I'm struggling with this command: awk '!/^\+/{ORS=FS}/^\+/{ORS=RS}1' file1 > file2 What I want to do is to move any line that starts with the + sign 1 up, so its the continuation of the previous. The above command is messing the whole output, can you please let me know... (8 Replies)
Discussion started by: demmel
8 Replies

3. Shell Programming and Scripting

Bash command line to strip tar.gz file extension?

What's the command syntax for stripping out the tar.gz file extension in a bash command line (not script file). Thanks! prompt/> ls *.tar.gz | <what comes here?> (3 Replies)
Discussion started by: ZillaG
3 Replies

4. HP-UX

Typing the @ sign creates new line.

Whenever I type the @ sign like for example when using a proxy ftp server, The system forces the cursor to jump to a new line. I know it has something to do with the terminal settings. How can I get this to stop and more importantly, how can I modify my profile to set this up whenever I login? ... (3 Replies)
Discussion started by: ricnetman
3 Replies

5. Shell Programming and Scripting

strip carriage return & append next line

Hello everyone, I am trying to search a file for lines that start with 'ip:' and have a carriage return after(ip:$). I then want to remove the carriage return from that line and append the next line in the file to the line containing 'ip'. I tried doing this with SED, but had no luck. Any... (3 Replies)
Discussion started by: vada010
3 Replies

6. Shell Programming and Scripting

Strip one line from 2 blank lines in a file

Hi Is there any command to scan thru a file looking for 2 consecutive blank lines and if any remove one of them. Please let me know. Regards, Tipsy (6 Replies)
Discussion started by: tipsy
6 Replies

7. Shell Programming and Scripting

how do i strip this line using perl regex.

I have a variable dynamically generated $batch = /dataload/R3P/interface/Bowne/reports/RDI00244.rpt Now I'd like to strip '/dataload/R3P/interface/Bowne/reports/RDI' and '.rpt' from this variable my output should be only 00244 how to do this using perl regex.I'm a newbie to perl and would... (1 Reply)
Discussion started by: ramky79
1 Replies

8. Shell Programming and Scripting

Need to strip a string

I have a file that looks like this: /home/fred/opt/bin /opt/usr/bin /usr/sbin/var/opt I need a way to chop of everything after the last occurance of the / sign including the /. So the file above will now look like this below. /home/fred/opt /opt/usr /usr/sbin/var I tried using... (6 Replies)
Discussion started by: x96riley3
6 Replies

9. Shell Programming and Scripting

Sign on/Sign off logging script

I'd like to make a script that I can execute every time I sign on to my linux box that keeps track of the time and allows to me to add a remark to a file. So basically once I log in, I run the script, and it outputs the date and time to a text file (log.txt). But that isn't my problem. I need... (1 Reply)
Discussion started by: Glider
1 Replies
Login or Register to Ask a Question