Sponsored Content
Top Forums Shell Programming and Scripting Stripping of a symbol from string not working properly Post 302615035 by rangarasan on Thursday 29th of March 2012 06:24:39 AM
Old 03-29-2012
sed

Quote:
Originally Posted by angie1234
Hi All,

I used this code to strip-off $-symbol from string values.

Code:
a="$980"
b="897"
a=`echo "$a" | sed 's/$/ /g'`
b=`echo "$b" | sed 's/$/ /g'`
echo "$a"
echo "$b"

but this results in the output:
80 and 897

it works when i use
Code:
a='$987'
b='890'

But I cannot use single-quotes in my actual code as the variable values are extracted as strings and are not constant.

Is there any other command or any fix for this ?
I even used 'tr', even that works similar to sed .
Try the way Scrutinizer suggested.
The reason behind for sed cmd not working is,
$ - has special meaning in sed( almost in all regex). so you have to put \ before using the special meaning characters.

Code:
a="\$980"
a=`echo "$a" | sed 's/\$/ /g'`

Cheers,
RangaSmilie
 

10 More Discussions You Might Find Interesting

1. Programming

y is this not working properly?

#include <stdio.h> #include <sys/types.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> struct stat s; main() { char c; if (fork()==0) { system("clear"); do { printf("myAI\\>§ "); scanf("%s",c); if(stat(c,&s)>-1) {... (3 Replies)
Discussion started by: C|[anti-trust]
3 Replies

2. UNIX for Dummies Questions & Answers

Stripping a portion of string from behind!!!

Hi, How to strip a portion of a file name from behind...Say for Eg..i have a file name like aaaaa.bbbbb.Mar-17-2007 i want to remove .Mar-17-2007...is there a one line command which can give this output... Thanks Kumar (5 Replies)
Discussion started by: kumarsaravana_s
5 Replies

3. Shell Programming and Scripting

stripping leftmost characters from string

Hi there, if i have some strings ie test_324423 test_242332 test_767667 but I only want the number part (the bolded bit) how do I strip the leftmost 5 characters from the output so that i will have just 324423 242332 767667 any help would be greatly appreciated Gary (5 Replies)
Discussion started by: hcclnoodles
5 Replies

4. Shell Programming and Scripting

Stripping the spaces in a string variable

Hi , i have to strip the spaces in the string which has the following value ABC DEF i want this to appear like this ABC DEF is there any spilt method? please help.... Thanks (3 Replies)
Discussion started by: rag84dec
3 Replies

5. Shell Programming and Scripting

stripping certain characters in at the middle of a string

I am trying to strip out certain characters from a string on both (left & right) sides. For example, line=see@hear|touch, i only want to echo the "hear" part. Well i have tried this approach: line=see@hear|touch templine=${line#*@} #removed "see@" echo ${templine%%\|*} #removed... (4 Replies)
Discussion started by: mcoblefias
4 Replies

6. Shell Programming and Scripting

\n not working properly

Hi all, I'm trying to generate a series of txt files starting from a plain csv file part of my code: #!/bin/ksh INSTALLDIR=/Users/ME/Installdir CSV=CSV.csv TMP=/tmp/$(basename $0).txt tr -s "\r" "\n" < /$INSTALLDIR/$CSV > $TMP function Makefiles { printf '%24s:%30s\n' "sometext"... (1 Reply)
Discussion started by: Jive Spector
1 Replies

7. Shell Programming and Scripting

stripping out digits from a string with sed

i want to parse a string and only display the digits in that string... How would i accomplish this with sed command. For example. input string: " 033434343 dafasdf" output string: 03343434 Thanks (2 Replies)
Discussion started by: timmylita
2 Replies

8. Linux

rexec not working properly

Hi, I am trying to enable rexec to automate certain tasks(it has to be rexec, not ssh or any other due to the system environment), so after switching to linux, I followed the certain instructions that were laid out in the web. My operating system is fedora 17, so I first installed the... (1 Reply)
Discussion started by: wringer
1 Replies

9. UNIX for Dummies Questions & Answers

~c is not working properly with -r option

Hi There, --------- file1 ------- ~c asd@ac.com -------------- Now i am using below command cat file1|mailx -s " testing" -r " My Name" abc@tech.com (3 Replies)
Discussion started by: Tapan Sharma
3 Replies

10. Shell Programming and Scripting

Expansion not working properly

I'm using an Ubuntu machine and expansion is not working properly. What would cause this? Do I need to check for any particular bash packages? $ ipcs -m | grep $USER | awk '{printf "%s ",$2}' $ ipcs -m | grep UNF | awk '{printf "%s ",$2}' 294912 1048577 425986 688131 786436 1245189... (14 Replies)
Discussion started by: cokedude
14 Replies
ar(4)							     Kernel Interfaces Manual							     ar(4)

NAME
ar - common archive file format SYNOPSIS
DESCRIPTION
The command is used to concatenate several files into an archive file (see ar(1)). Archives are used mainly as libraries to be searched by the link editor (see ld(1)). Each archive begins with the archive magic string. Following the archive magic string are the archive file members. Each file member is preceded by a file member header which is of the fol- lowing format: All information in the file member headers is in printable ASCII. The numeric information contained in the headers is stored as decimal numbers (except for which is in octal). Thus, if the archive contains printable files, the archive itself is printable. The contents of the field are slash terminated and blank-padded. The field is the modification date of the file at the time of its inser- tion into the archive. Common format archives can be moved from system to system as long as the portable archive command is used. Note that older versions of did not use the common archive format, and those archives cannot be read or written by the common archiver. Each archive file member begins on an even byte boundary; a new-line character is inserted between files if necessary. Nevertheless, the size given reflects the actual size of the file exclusive of padding. Notice there is no provision for empty areas in an archive file. If the archive symbol table exists, the first file in the archive has a zero-length name (i.e., and The contents of this archive member are machine-dependent. Refer to the appropriate a.out(4) manual entry for more information. Each archive which contains object files (see a.out(4)) may include an archive symbol table. This symbol table is used by the link editor (see ld(1)) to determine which archive members must be loaded during the link edit process. The archive symbol table (if it exists) is always the first member in the archive (but is never listed) and is automatically created and/or updated by If a member with a file name greater than 15 bytes exists within the archive, then the archive will also contain an additional special mem- ber to store the long file name string table. The special string table member has a zero length name where and If a special string table exists, it will precede all non-special archive members. If both a symbol table member and a string table member exist then the symbol table member will always precede the string table member. Each entry in the string table is followed by a slash and a new-line character. The offset of the table begins at zero. If an archive mem- ber name exceeds 15 bytes, then the entry in the member's header does not contain a name, instead it contains the offset into the string table preceded by a slash. For example, the member name contains in the field. This value represents the offset into the string table. The member name contains in the field. The long name string table would have the following format: +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +---------------------------------------------------------- 0| t | h | i | s | i | s | a | v | e | r | +---------------------------------------------------------- 10| y | l | o | n | g | f | i | l | e | n | +---------------------------------------------------------- 20| a | m | e | . | o | / | | y | e | t | +---------------------------------------------------------- 30| a | n | o | t | h | e | r | l | o | n | +---------------------------------------------------------- 40| g | f | i | l | e | n | a | m | e | . | +---------------------------------------------------------- 50| o | / | | +---------------- SEE ALSO
System Tools: ar(1) create archived libraries ld(1) invoke the link editor Miscellaneous: a.out(4) assembler, compiler, and linker output magic(4) magic number for HP-UX implementations ranlib(1) regenerate an archive symbol table strip(1) strip symbol and line number information from an object file CAVEATS
removes the archive symbol table member from the archive (see strip(1)). The archive symbol table must be restored by using the option of the command or the ranlib(1) command before the archive can be used with the link editor. ar(4)
All times are GMT -4. The time now is 09:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy