Sponsored Content
Top Forums Shell Programming and Scripting shell script to remove the last character(.) of a string Post 302380960 by ichigo on Wednesday 16th of December 2009 06:21:28 PM
Old 12-16-2009
Code:
gawk '{for(o=1;o<=NF;o++){ sub(/\.$/,"",$o) } }{print} ' file

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script: Cut / (slash) character in string

I have a string "\/scratch\/databases\". I want to have a new string "\/scratch\/databases" by cutting last '\' character using shell script. I can't do this Please help me. Thanks in advance ThuongTranVN (4 Replies)
Discussion started by: ThuongTranVN
4 Replies

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

3. Shell Programming and Scripting

How to remove last character in a string read from file

Hello, The last character is a comma , I have tried the following: sed -e 's/\,$//' filename-to-read however - there are still commas at the end of each line...:confused: (5 Replies)
Discussion started by: learning
5 Replies

4. Shell Programming and Scripting

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: 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... (1 Reply)
Discussion started by: KatieV
1 Replies

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

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

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

8. Shell Programming and Scripting

gawk to remove last character in a line or string

I am outputting a line like this print $2 "/" $4The last character though is a ":" and I want to remove it. Is there any neat way to remove it? Or am I forced to do something like this: print $2 "/" substr($4, 1, length($4) - 1)Thanks. (6 Replies)
Discussion started by: benalt
6 Replies

9. Shell Programming and Scripting

Shell script remove bad character

I was curious to know how to write into my shell script to remove a character. The character I want to remove is  within a .html file. (18 Replies)
Discussion started by: graphicsman
18 Replies

10. 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
wordexp(3C)															       wordexp(3C)

NAME
wordexp(), wordfree() - perform word expansions SYNOPSIS
DESCRIPTION
performs word expansions and places the list of expanded words into the structure pointed to by pwordexp. The words argument is a pointer to a string containing one or more words to be expanded. The expansions are the same as would be performed by the shell (see sh-posix(1)), if words were the part of a command line representing the arguments to a utility. Therefore, words must not contain an unquoted newline character or any of the unquoted shell special characters or except in the context of shell command substi- tution. If words contains an unquoted comment character, it is treated as the beginning of a token that interprets as a comment indicator, causing the remainder of words to be ignored. The structure type is defined in the header and includes the following members: A used to keep count of words matched by words. A used as a pointer to a list of expanded words. Also a used to indicate the number of slots to reserve at the beginning of stores the number of generated words into Each individual field created during field splitting or path name expansion is a separated word in the list. The words are in order as described in shell word expansions. The first pointer after the last word pointer is a null pointer. The expansion of special parameters (such as $$ or $*) is unspecified. It is the caller's responsibility to allocate the storage pointed to by pwordexp. allocates other space as needed, including memory pointed to by frees any memory associated with pwordexp from a previous call to The flags argument is used to control the behavior of The value of flags is the bitwise inclusive OR of zero or more of the following con- stants, which are defined in Append words generated to the ones from a previous call to Make use of If this flag is set, is used to specify how many null pointers to add to the beginning of In other words, points to null pointers, followed by word pointers, followed by a null pointer. Fail if command substitution is requested. The pwordexp argument was passed to a previous successful call to and has not been passed to The result is the same as if the application had called and then called without Do not redirect stderr to Report error on an attempt to expand an undefined shell variable. The flag can be used to append a new set of words to those generated by a previous call to The following rules apply when two or more calls to are made with the same value of pwordexp and without intervening calls to o The first call must not set All subsequent calls must set it. o All of the calls must set or all must not set it. o After the second and each subsequent call, points to a list containing the following: o Zero or more null pointers, as specified by and o Pointers to the words that were in the list before the call, in the same order as before. o Pointers to the new words generated by the latest call, in the specified order. o The count returned in is the total number of words from all of the calls. o The application can change any of the fields after a call to but if it does, it must reset them to the original value before a subsequent call, using the same pwordexp value, to or with the or flag. If words contains an unquoted newline, parentheses, or curly brackets in an inappropriate context, fails, and the number of expanded words is zero. Unless is set in flags, redirects stderr to for any utilities executed as a result of command substitution while expanding words. If is set, writes messages to stderr if syntax errors are detected while expanding words. If is set, has the same value for each call and the call using a given RETURN VALUE
Upon successful completion, returns zero; otherwise, it returns a nonzero value defined in to indicate the error: One of the unquoted characters parentheses, or braces appears in words in an inappropriate context. Reference to undefined shell variable when is set in flags. Command substitution requested when was set in flags. Attempt to allocate memory failed. Shell syntax error such as unbalanced parentheses or unterminated string. Internal error. If returns the error value and are updated to reflect any words that were successfully expanded. In other cases, they are not modified. AUTHOR
and were developed by OSF and HP. SEE ALSO
sh-posix(1), fnmatch(3C), glob(3C), regexp(5), thread_safety(5). STANDARDS CONFORMANCE
wordexp(3C)
All times are GMT -4. The time now is 08:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy