in Education by
Hi I want to remove last comma from a line. For example: Input: This,is,a,test Desired Output: This,is,a test I am able to remove last comma if its also the last character of the string using below command: (However this is not I want) echo "This,is,a,test," |sed 's/,$//' This,is,a,test Same command does not work if there are more characters past last comma in line. echo "This,is,a,test" |sed 's/,$//' This,is,a,test I am able to achieve the results using dirty way by calling multiple commands, any alternative to achieve the same using awk or sed regex ?(This is I want) echo "This,is,a,test" |rev |sed 's/,/ /' |rev This,is,a test JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
$ echo "This,is,a,test" | sed 's/\(.*\),/\1 /' This,is,a test $ echo "This,is,a,test" | perl -pe 's/.*\K,/ /' This,is,a test In both cases, .* will match as much as possible, so only the last comma will be changed.

Related questions

0 votes
    Given a string file path such as /foo/fizzbuzz.bar, how would I use bash to extract just the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    How will you remove last object from a list in Python?...
asked Nov 26, 2020 in Technology by JackTerrance
0 votes
    This is my function: def sub(number): tmp = [] tmp.append(number) while len(str(number)) > 1: tmp.append( ... do this in the python? Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I have a set of oil wells compiled in the panda's data frame. It looks like this: wells = pd.DataFrame({'date ... -01-01 FIELDZ 10.8 Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I am trying to print a particular text using awk if string is empty. It works fine in the below ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 13, 2022 in Education by JackTerrance
0 votes
    How to handle comma within a field while uploading using Data Loader?...
asked Nov 11, 2020 in Technology by JackTerrance
0 votes
    Is it possible to remove ( not hide using display:none ) some part of HTML from source for mobile ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 15, 2022 in Education by JackTerrance
0 votes
    I am learning bash scripting. While exploring the math functions i am came across a command which calculated ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I need to replace each character of a regular expression, once evaluated, with each character plus the @ ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I need to replace each character of a regular expression, once evaluated, with each character plus the @ ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    What would be your preferred way to concatenate strings from a sequence such that between every two consecutive ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I have uploaded a Directory to hadoop cluster that is having "," in its name like "MyDir, Name" when I ... such kind of Directories. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    What is the Git command to view the last three commits in a line? A. git last 3 commits B. git log -–oneline -3 C. git show log -3 D. git log...
asked Dec 23, 2022 in Technology by JackTerrance
0 votes
    What is the Git command to view the last 3 commits in one line ? A. git show log -3 B. git last 3 commits C. git log D. git log -–oneline -3...
asked Dec 21, 2022 in Technology by JackTerrance
...