sed situation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed situation
# 1  
Old 10-04-2006
Question sed situation

Hi,

I'm looking for someone who can think in sed. Basically, I need the trailing characters on every line in a file to be deleted. These characters are all in capitals, and always follow a number, but they often vary in number

For instance, on the line:

2006_10_9_p20_TALK

I'd want to remove the _TALK. And on the line

2006_10_9_p119_CRITICS

I'd want to remove the _CRITICS. I'm reasonably good with sed basics, but no guru. Any suggestions?

Best wishes
Laurel Maury
# 2  
Old 10-04-2006
Not knowing the exact format of your file, this might work, or at least point you in the right direction:
Code:
echo "2006_10_9_p119_CRITICS" | sed 's/_[A-Z][A-Z]*$//g'

Result: 2006_10_9_p119
# 3  
Old 10-04-2006
Quote:
Originally Posted by Glenn Arndt
Not knowing the exact format of your file, this might work, or at least point you in the right direction:
Code:
echo "2006_10_9_p119_CRITICS" | sed 's/_[A-Z][A-Z]*$//g'

Result: 2006_10_9_p119
In this case the g is not required since there will be only one match:

Code:
echo "2006_10_9_p119_CRITICS" | sed 's/_[A-Z][A-Z]*$//'

would be sufficient, this should also work:

Code:
echo "2006_10_9_p119_CRITICS" | sed 's/[^0-9]*$//'

# 4  
Old 10-04-2006
This might also help you

Code:
$ echo "2006_10_9_p119_CRITICS" | sed 's/^\(.*\)_.*$/\1/'
2006_10_9_p119
$ echo "2006_10_9_p20_TALK" | sed 's/^\(.*\)_.*$/\1/'
2006_10_9_p20

# 5  
Old 10-05-2006
try this

file txt content
2006007 20001 AR 2502_TXT
2006007 20001 AU 2502_TXT
2006007 20001 CL 2502_TXT
2006007 20001 CO 2502_TXT1
2006007 20001 ES 2502_TXT

sed 's/^\(.*\)_\([A-Z]*\)$/\1/' txt
ouput :
2006007 20001 AR 2502
2006007 20001 AU 2502
2006007 20001 CL 2502
2006007 20001 CO 2502_TXT1

above command will only delete those line which matches the pattern "_[A-Z]"
--Manish
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Have a situation while extracting info

i have a text file which i am generating from few sqls. format is like : col1 col2 col3 col4 col5 1001 DONE ABC 17-sep-14 12:02:05 1001 DONE ABC 17-sep-14 12:02:05 1001 DONE ABC 17-sep-14 12:02:55 1001 REDONE ABC ... (6 Replies)
Discussion started by: deepakiniimt
6 Replies

2. Shell Programming and Scripting

Cat files situation

Hello, I am PhD student (Biomedical sciences) and very new to Linux. I need some help with the following task : I have files in the following format for their names : An_A1_nnn_R1.txt; An_A1_nnm_R1.txt; An_A1_nnoo_R1.txt An_A2_nnn_R1.txt; An_A2_nnm_R1.txt; An_A2_nno_R1.txt ... (8 Replies)
Discussion started by: Julio Finalet
8 Replies

3. HP-UX

Tricky situation getting IP address

Hi, I have a multihomed system HP-UX with two NIC cards having IP address 10.9.0.13 & 10.9.0.45 I have two weblogic servers running one listening on "10.9.0.13" and the other on "10.9.0.45" Given a PID how is it possible to extract the IP Address that the weblogic server is using and... (1 Reply)
Discussion started by: mohtashims
1 Replies

4. UNIX for Advanced & Expert Users

Questions regarding a PANIC situation

Hi, Last week, we experienced 2 KERNEL PANIC error on our SCO Unix 5.0.7 server within a 2 hour span. So I called our sofware support which is OGC using running on an Informix Database. Within 5 minutes I had as answer that the problem was an Hardware issue. Since the server is supported by... (4 Replies)
Discussion started by: adamsville2k
4 Replies

5. UNIX for Dummies Questions & Answers

help : crisis situation !!

Hi I had deleted important files from my company server :( the server is HPUX and i don't know how to undo rm command or how to restore the files .. iam appreciate for any help Thanx ... (5 Replies)
Discussion started by: Eisa
5 Replies

6. Shell Programming and Scripting

How to Sort a file for given situation?

Hi All, How can you sort a file that is doubled space ( where even number lines are blank lines) and still preserves the blank lines? You can use grep,sed and regular expression. Thanks Vishal (4 Replies)
Discussion started by: vishalpatel03
4 Replies

7. Programming

strange situation in file

Hi All, I am writing some data's into a file from C++ program. The files which i am writing is of fixed length . say 232 in length per line. I am writing as . my c code is as ... (0 Replies)
Discussion started by: arunkumar_mca
0 Replies

8. UNIX for Dummies Questions & Answers

sed substitute situation

I am having a problem executing a sed substitute in a file. I have tried alot of different things I found in previous posts, however non seem to work. I want to substitute this in $FILE: VALUE=33.4 In the script I have tried the following: prev=$(awk -F"=" '{ print $2 }' $FILE ) new=$(echo... (16 Replies)
Discussion started by: newbreed1
16 Replies

9. UNIX for Advanced & Expert Users

current situation

hello..what is the current situation or lastest version of UNIX?? Is there any where i can read more about it?? (2 Replies)
Discussion started by: joanne6298
2 Replies

10. UNIX for Dummies Questions & Answers

A Challenging situation for the MODERATORS

Well, I hope this way you will respond to my inquiries. I have 4 unix servers,with static ips (though i dont think this is an issue)....i can telnet and rlogin from one to the other....if i FTP from on et othe other and try to execute : cd /user return /user : no such file or... (1 Reply)
Discussion started by: BAM
1 Replies
Login or Register to Ask a Question