Delete character from a word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete character from a word
# 1  
Old 09-30-2009
Delete character from a word

Friends, I'm looking for a command that delete the first tho caractere in a word. Here is an exp :

I want to replace "20091001" by "091001"

or "replace" by "place"

Thx,
# 2  
Old 09-30-2009
By GNU date

Code:
date -d 20091001 "+%y%m%d"

091001

Or by Awk:

Code:
echo "20091001" | awk '{print substr($1,length($1)-5)}'


Last edited by rdcwayx; 09-30-2009 at 11:22 PM..
# 3  
Old 09-30-2009
Thank you,

In fact i'm trying to get time 15 min ago, so i'm using this command :

feefth=`perl -e '($s,$m,$h,$J,$M,$A) = localtime(time - 15*60) and printf("%d%02d%02d%02d%02d\n",$A+1900,$M+1,$J,$h,$m)'`


But the result is : 20091001.0155

I need it to be only : 0910010155
# 4  
Old 10-01-2009
with GNUdate

Code:
$ date  +%Y%m%d%H%M
200910011306

$ date -d "15 minutes ago" +%y%m%d%H%M
0910011251

# 5  
Old 10-01-2009
Thank you, it's working !
# 6  
Old 10-01-2009
Quote:
Originally Posted by newpromo
In fact i'm trying to get time 15 min ago
I just ask myself what is the relationship between your thread title and your problem Smilie
# 7  
Old 10-01-2009
In fact i tried to make my request more general to make it easy for you to help me, i give two exp : "20091001" by "091001" and "replace" by "place"

deleting the caracteres "20" from the word "20091001" to be "091001"

and deleting the caracteres "re" from the word "replace" tp be "place".

I found also an other solution by leaving "20" static in my script because it's not going to change very soon !!!

Anyway, thanks for your help and i'm very glad to have a quick answer to my first post Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Remove word before a character

Hi, I have a file which looks like this id integer, name string, create_dt date, I want to remove all words that are present before the character , My output should be id, name, create_dt, Thanks wah (2 Replies)
Discussion started by: wahi80
2 Replies

3. Shell Programming and Scripting

Position of character in word

How can I represent the position of 1 (considering only the 1s after the colon) in the word from field5 and above; counting from right to left. Input: TT-124 06-03-14 08-02-10 FAS CAT1:10 TT-125-1 05-03-14 10-06-08 CAS CAT2:1010 FAT1:10000 TT-125-3 07-03-14 11-02-06 FAS FAT1:1101... (6 Replies)
Discussion started by: aydj
6 Replies

4. Shell Programming and Scripting

Sed: delete on each line before a character and after a character

Hi there, A total sed noob here. Is there a way using sed to delete everything before a character AND after another character on each line in a file? The deletion should also delete the indicating characters(here: an opening and a closing parenthesis). The original file would look like... (3 Replies)
Discussion started by: bnbsd
3 Replies

5. Shell Programming and Scripting

How can we get the character before and after a word in a string?

Hi friends, I am working in a korn shell. i want to know the command which gives me the previous one character and next one character of a given keyword in a string? for exmaple: input string: /bin/dir/folder1/.proc_name^folderone Keyword: proc_name output : .^ ... (10 Replies)
Discussion started by: neelmani
10 Replies

6. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

7. Shell Programming and Scripting

How to chose certain character in a word?

Hi Expert, I would like to know on how to export only the first 6 character of below 0050569868B7 ABCDEFGHTY to 005056 ABCDEF Thank you. Reggy (7 Replies)
Discussion started by: regmaster
7 Replies

8. Shell Programming and Scripting

Command to parse a word character by character

Hi All, Can anyone help me please, I have a word like below. 6,76 I want to read this word and check if it has "," (comma) and if yes then i want to replace it with "." (dot). That means i want to be changed to 6.76 If the word doesnot contain "," then its should not be changed. Eg. ... (6 Replies)
Discussion started by: girish.raos
6 Replies

9. UNIX for Dummies Questions & Answers

How to delete all character before certain word

Hi, For example, i have a string "123 456 789 abc 111 222 333" and I would like to delete all the characters before abc so that it becomes "abc 111 222 333" how can i do that in unix? using sed? note: I actually don't know how many words/charachters before "abc", so the "cut"... (9 Replies)
Discussion started by: phandy
9 Replies

10. UNIX for Dummies Questions & Answers

Delete between 10th character and 20th character

Hi, I have a .txt and I need to delete the characters betwwen the 10th and 20th... How can I do that... I need to do somethink like these: %s/I don't know how to define a range between 10th and 20th character//g Can you help me... If I want the 10 first characters i do this:... (2 Replies)
Discussion started by: nuno_fbo
2 Replies
Login or Register to Ask a Question