Sed is doing my head in! How do you remove the first character of a string?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed is doing my head in! How do you remove the first character of a string?
# 1  
Old 09-22-2010
Power [Solved] Sed is doing my head in! How do you remove the first character of a string?

Hello!

Please bare with me, I'm a total newbie to scripting. Here's the sudo code of what I'm trying to do:
Code:
Get file name

Does file exist?

If true
     get length of file name

     get network id (this will be the last 3 numbers of the file name)

     loop x 2

          If first character of if :=0

               delete first character
          else
               exit loop
           fi
     end loop

Currently I have:

Code:
[-f /var/named/$Server ] && flag="true" || flag="false"

if $flag
then
     echo "yey"

     length=$((${#s}-2))
     ipmid='expr substr $s $((length)) 3'

     if [ ${ipmid:0:1} = 0 ]
     then
          ????
     fi
else
echo "Something went wrong! Whoops!"
fi

exit 0

with the s variable being the user input which looks like "test001" or "testtwo010"

As you can see I'm having trouble with the sed that will chop of the first character.
I tried :
Code:
echo $ipmid | cut -c2-

but that will print the last 2 characters but not chop off the first.
Ive also tried hacking as sed with
Code:
$ipmid | sed 's/.\(.*\)/\1/'

but that just gets me an error Smilie Smilie

Thanks!

Katie

---------- Post updated at 10:59 AM ---------- Previous update was at 10:16 AM ----------

fixed it, Thanks, and sorry for clogging up your threads!

If anyone is interested the solution is:
Moderator's Comments:
Mod Comment Yes - We are always...

Code:
ipmid=${ipmid#?}


Last edited by vbe; 09-22-2010 at 07:15 AM.. Reason: code tags please
# 2  
Old 09-22-2010
Thanks for sharing, we can the add Solved to the title for the search engines...And we always like to know how...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to remove first and last character using sed

Hi I have file in below format. How i can remove the first and lost comma from this below file ,001E:001F,,,02EE,0FED:0FEF, I need output has below 001E:001F,,,02EE,0FED:0FEF (6 Replies)
Discussion started by: ranjancom2000
6 Replies

2. UNIX for Beginners Questions & Answers

Remove string between number and character

hello ! I have to remove string between a number and set of characters. For example, 35818 -stress - - -stress - - - - - - DB-3754 44412 caul kid notify DB-3747 54432 roberto -, notify DB-3725 55522 aws _ _int _ _classified 2_a _a 2_m _m 2_classified 2_search... (7 Replies)
Discussion started by: ManoharMa
7 Replies

3. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

4. Shell Programming and Scripting

Remove last occurrence of character (_) and rest of the string in UNIX (sed)

Hi I need help on this ..!! Input : xx_abc_regA xx_def_regB xx_qwe_regC Now i required the output as the below abc def qwe Need to remove last occurrence of character (_) and rest of the string in Unix (sed). Thanks in Advance ..!!! -Nallachand (3 Replies)
Discussion started by: Nallachand
3 Replies

5. Shell Programming and Scripting

Need to remove a character using sed

Hi All, I have output like this below ldprod/03 ldprod/02 ldprod/01 ldprod/00 ldnprod/ ldnprod/030 I want only remove all character including / ldprod ldprod ldprod ldprod ldprod ldnprod (8 Replies)
Discussion started by: ranjancom2000
8 Replies

6. Shell Programming and Scripting

Bash: How to remove the last character of a string?

In bash, how can one remove the last character of a string? In perl, the chop function would remove the last character. However, I do not know how to do the same job in bash. Many thanks in advance. (12 Replies)
Discussion started by: LessNux
12 Replies

7. Shell Programming and Scripting

remove the first and last character of a string

How can i remove the first and last character of strings like below: "^^^613*" "admt130" "^^^613*" "123456" "adg8484" "DQitYV09dh1C" Means i wanna remove the quotes(""). Please help (17 Replies)
Discussion started by: proactiveaditya
17 Replies

8. Shell Programming and Scripting

remove all occurrences of a character at the beginning of a string

Hi there, i need some help to remove all occurrences of a certain character at the beginning of a string. Example: my string is 00102030 and i want to remove all zeros from beginning of string so the result is 102030 (3 Replies)
Discussion started by: gigagigosu
3 Replies

9. Shell Programming and Scripting

How to remove the first character on a string in a variable

Hi all, Does anyone know how to code in ksh that will remove the first character in a string variable and replace that variable without the first character? Example: var1=ktest1 will become var1=test1 var2=rtest2 will become var2=test2 Need help please. (10 Replies)
Discussion started by: ryukishin_17
10 Replies

10. Shell Programming and Scripting

sed to remove character ['

I have a huge file where the each column has data in the format: . I want to remove the from each value. How do I do it with sed? thanks (2 Replies)
Discussion started by: manishabh
2 Replies
Login or Register to Ask a Question