Sponsored Content
Top Forums UNIX for Beginners Questions & Answers sed script to delete the last word after a last pattern match Post 303033230 by kshitij on Tuesday 2nd of April 2019 01:41:47 AM
Old 04-02-2019
sed script to delete the last word after a last pattern match

Hi Guys ,

I am having a file as stated below

File 1

Code:
sa0   --   i_core/i_core_apb/i_afe0_controller/U261/A
 sa0   --   i_core/i_core_apb/i_afe0_controller/U265/Z
 sa1   --   i_core/i_core_apb/i_afe0_controller/U265/A
 sa1   --   i_core/i_core_apb/i_afe0_controller/U268/Z
 sa1   --   i_core/i_core_apb/i_afe0_controller/U268/A
 sa1   --   i_core/i_core_apb/i_afe0_controller/U273/Z
sa0   --   i_core/i_core_ahb/i_hebi/i_hsdramc1/i_hsdramc1_ocms_scrambler/ext_key_regx63x/D
 sa1   AN   i_core/i_core_ahb/i_hebi/i_hsdramc1/i_hsdramc1_ocms_scrambler/ext_key_regx63x/SE

I want to search the last "/" in each and every line and delete the last word after that including last "/"

Output


Code:
sa0   --   i_core/i_core_apb/i_afe0_controller/U261
 sa0   --   i_core/i_core_apb/i_afe0_controller/U265
 sa1   --   i_core/i_core_apb/i_afe0_controller/U265
 sa1   --   i_core/i_core_apb/i_afe0_controller/U268
 sa1   --   i_core/i_core_apb/i_afe0_controller/U268
 sa1   --   i_core/i_core_apb/i_afe0_controller/U273
sa0   --   i_core/i_core_ahb/i_hebi/i_hsdramc1/i_hsdramc1_ocms_scrambler/ext_key_regx63x
 sa1   AN   i_core/i_core_ahb/i_hebi/i_hsdramc1/i_hsdramc1_ocms_scrambler/ext_key_regx63x

Could you help me out?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to delete lines do NOT match a pattern

On Unix, it is easy to get those lines that match a pattern, by grep pattern file or those lines that do not, by grep -v pattern file but I am editing a file on Windows with Ultraedit. Ultraedit support regular expression based search and replace. I can delete all the lines that match a... (1 Reply)
Discussion started by: JumboGeng
1 Replies

2. Shell Programming and Scripting

SED: match pattern & delete matched lines

Hi all, I have the following data in a file x.csv: > ,this is some text here > ,,,,,,,,,,,,,,,,2006/11/16,0.23 > ,,,,,,,,,,,,,,,,2006/12/16,0.88 < ,,,,,,,,,,,,,,,,this shouldnt be deleted I need to use SED to match anything with a > in the line and delete that line, can someone help... (7 Replies)
Discussion started by: not4google
7 Replies

3. Shell Programming and Scripting

Sed to delete exactly match pattern and print them in other file

Hi there, I need help about using sed. Iam using sed to delete and print lines that match the port number as listed in sedfile. I am using -d and -p command for delete match port and print them respectively. However, the output is not synchonize where the total deleted lines is not similar with... (3 Replies)
Discussion started by: new_buddy
3 Replies

4. Shell Programming and Scripting

delete a line that does not match the pattern

hi, i am parsing a file, in that searching for lines those contains "$threadNo.Received message:" , if that line contains the required fields write them into a separate file other wise ignore them. i am using the following code,but it is printing all the lines , i dont want to rpint , please help... (3 Replies)
Discussion started by: Satyak
3 Replies

5. Shell Programming and Scripting

Replace 1 word after pattern match

Hi, Here is my pattern CREATE USER LZ IDENTIFIED BY VALUES 'A0144280ESD70' DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP1 PROFILE DEVELOPER_D_1 ACCOUNT UNLOCK / The Sed command must look for the Line that contains TEMPORARY TABLESPACE and replace the immediate word... (4 Replies)
Discussion started by: rajan_san
4 Replies

6. Shell Programming and Scripting

Search word in a line and print earlier pattern match

Hi All, I have almost 1000+ files and I want to search specific pattern. Looking forwarded your input. Search for: word1.word2 (Which procedure contain this word, I need procedure name in output. Expected output: procedure test1 procedure test2 procedure test3 procedure test4 ... (7 Replies)
Discussion started by: susau_79
7 Replies

7. Shell Programming and Scripting

print word after pattern match in two instances

i have a file like below. how can i printout the digits followed by the pattern -bwout and -bwin. say i run the script by entering line number 145 (the fourth line), then the o/p should be like 5000000 1024000 8 test1 -ipprot erp -ppsout 500 -ppsin 500 -bwout 300000 -bwin 300000 -statsdevice... (7 Replies)
Discussion started by: sb245
7 Replies

8. Shell Programming and Scripting

how to convert a shell script to a php script for displaying next word after pattern match

I have a shell script which I made with the help of this forum #!/bin/sh RuleNum=$1 cat bw_rules | sed 's/^.*-x //' | awk -v var=$RuleNum '$1==var {for(i=1;i<=NF;i++) {if($i=="-bwout") print $(i+3),$(i+1)}}' Basically I have a pages after pages of bandwidth rules and the script gives... (0 Replies)
Discussion started by: sb245
0 Replies

9. Shell Programming and Scripting

Sed delete blank lines upto first pattern match

Hi Im trying to do the following in sed. I want to delete any blank line at the start of a file until it matches a pattern and then stops. for example: Input output: I have got it to work within a range of two patterns with the following: sed '/1/,/pattern/{/^]*$/d}' The... (2 Replies)
Discussion started by: duonut
2 Replies

10. Shell Programming and Scripting

sed : match one pattern then the next consecutive second pattern not working

Ive used this snippet of code on a solaris box thousands of times. But it isnt working on the new linux box sed -n '/interface LoopBack0/{N;/ ip address /p;}' *.conf its driving me nuts !! Is there something Im missing ? (7 Replies)
Discussion started by: popeye
7 Replies
SYSSTAT(5)							Linux User's Manual							SYSSTAT(5)

NAME
sysstat - sysstat configuration file. DESCRIPTION
This file is read by sa1(8) and sa2(8) shell scripts from the sysstat's set of tools. It consists of a sequence of shell variable assign- ments used to configure sysstat logging. The variables and their meanings are: HISTORY The number of days during which a daily data file or a report should be kept. Data files or reports older than this number of days will be removed by the sa2(8) shell script. COMPRESSAFTER Number of days after which daily data files are to be compressed, either by gzip or bzip2. SADC_OPTIONS Options that should be passed to sadc(8). With these options (see sadc(8) manual page), you can select some additional data which are going to be saved in daily data files. These options are used only when a new data file is created. They will be ignored with an already existing one. FILES
/etc/sysstat/sysstat AUTHOR
Sebastien Godard (sysstat <at> orange.fr) SEE ALSO
sadc(8), sa1(8), sa2(8) http://pagesperso-orange.fr/sebastien.godard/ Linux SEPTEMBER 2010 SYSSTAT(5)
All times are GMT -4. The time now is 07:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy