Remove apostrophe and a letter followed by it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove apostrophe and a letter followed by it
# 1  
Old 09-30-2011
Remove apostrophe and a letter(s) followed by it

Hi All,

For example, I have some words like these:

Code:
cabinet's
school's
field's
you'll

I know how to remove apostrophe from these words using this command:

Code:
cat filename | tr -s "\'" ' '

But I am not sure how I can remove the letter followed by the apostrophe, so that my output becomes:


Code:
cabinet
school
field
you

I am doing this in Linux with BASH.

Last edited by shoaibjameel123; 09-30-2011 at 01:31 AM.. Reason: Added more information
# 2  
Old 09-30-2011
Code:
$ sed "s/'[A-Za-z]//g" inputfile
cabinet
school
field

---------- Post updated at 10:03 AM ---------- Previous update was at 10:02 AM ----------

Code:
 
$ sed "s/'[A-Za-z].*//g" test
cabinet
school
field
you

$ cat test 
cabinet's
school's
field's
you'll

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 09-30-2011
using awk ..
Code:
$ awk -F\' '{print $1}' infile

This User Gave Thanks to jayan_jay For This Post:
# 4  
Old 09-30-2011
you can try this :
Code:
cat t1.txt | tr "\'" " " | cut -d " " -f 1

---------- Post updated at 01:47 AM ---------- Previous update was at 01:46 AM ----------

t1.txt - will be your input file


Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by Franklin52; 09-30-2011 at 03:51 AM.. Reason: Please use code tags, thank you
This User Gave Thanks to dnam9917 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find ' (apostrophe) by grep

hi linux expert how can i find apostrophe (') symbol in text file by grep? for example for find 'test, the command grep " \'test" * is not useful. Many Thanks samad (1 Reply)
Discussion started by: abdossamad2003
1 Replies

2. UNIX for Beginners Questions & Answers

Usage of sed, position of apostrophe

Hello, I have never ever seen below notation for string substitution. sed -i -e 's/tttt/pppp'/g /var/bin/czech.sh; The strange thing for me is the position of the apostrophe. Should it be before the / or after the g? If I had been writing that command line, I would have chosen below way:... (3 Replies)
Discussion started by: baris35
3 Replies

3. Shell Programming and Scripting

Remove repeated letter words

Hi, I have this text file with these words and I need help with removing words with repeated letter from these lines. 1 ama 5 bib 29 bob 2 bub 5 civic 2 dad 10 deed 1 denned 335 did 1 eeee 1 eeeee 2 eke 8... (4 Replies)
Discussion started by: crepe6
4 Replies

4. Shell Programming and Scripting

Replace specific letter in a file by other letter

Good afternoon all, I want to ask how to change some letter in my file with other letter in spesific line eg. data.txt 1 1 1 0 0 0 0 for example i want to change the 4th line with character 1. How could I do it by SED or AWK. I have tried to run this code but actually did not... (3 Replies)
Discussion started by: weslyarfan
3 Replies

5. Shell Programming and Scripting

Remove letter from $1 using awk or sed

I have a file: 575G /local/mis/SYBDUMP I want to remove the G, K, M or T so I can use $1 in awk or sed to do math. I want to end up with a file containing: 575 /local/mis/SYBDUMP It should not matter how small or large the numeric numbers are so if 2, 3, 4, or 5 digits etc I want to see... (9 Replies)
Discussion started by: tamvgi
9 Replies

6. Shell Programming and Scripting

Replace apostrophe with backslash apostrophe

I'm coding using BASH and have a requirement to replace apostrophes with backslash apostrophes. For example below: I am here 'in my room' ok Would be changed to: I am here /'in my room/' ok The original text is coming from a field in a MySql database and is being used by another process that... (5 Replies)
Discussion started by: dbjock
5 Replies

7. Shell Programming and Scripting

Perl - Title Case after apostrophe

I've got: $string =~ s/(\w+)/\u\L$1/g; Which capitalizes each word in the string. The problem is if I have a string with an apostrophe the first letter after it gets capitalized as well. So Bob's becomes Bob'S. Thanks for any quick fixes! (4 Replies)
Discussion started by: mjmtaiwan
4 Replies

8. Shell Programming and Scripting

script to replace a character with '(Apostrophe)

Hi Friends, I need a sed or awk based script to replace a character(alphabet) with ' (Apostrophe). I tried to use the following two commands 1) sed -e 's/a/'/' filename 2) awk '{sub("a","'",$1);print}' filename but both got failed. Any help on this. Thanks in advance.. (3 Replies)
Discussion started by: ks_reddy
3 Replies

9. Shell Programming and Scripting

Escaping apostrophe using shell script

Hi, I am using the KSH shell. I am facing a problem of escaping apostrophe('), that is occuring in a variable. I used the following command, but in vain item=`echo $item|sed 's/'/\'/g'` this code replaces the occurance of ' in an xml file to apostrophe(') symbol. The output of... (2 Replies)
Discussion started by: mradul_kaushik
2 Replies

10. Shell Programming and Scripting

How to strip apostrophe from a file

I am trying to remove or replace various extraneous characters from a file so that subsequent processes work correctly. The characters that is giving me trouble is the apostrophe '. The command I 'm trying is sed 's/\'//g' ${IN_WRK_DIR}/file1 > ${IN_WRK_DIR}/file2 in a Korn script on HP... (8 Replies)
Discussion started by: aquimby
8 Replies
Login or Register to Ask a Question