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
SA1(8)								Linux User's Manual							    SA1(8)

NAME
sa1 - Collect and store binary data in the system activity daily data file. SYNOPSIS
/usr/lib/sysstat/sa1 [ --boot | interval count ] DESCRIPTION
The sa1 command is a shell procedure variant of the sadc command and handles all of the flags and parameters of that command. The sa1 com- mand collects and stores binary data in the /var/log/sysstat/sadd file, where the dd parameter indicates the current day. The interval and count parameters specify that the record should be written count times at interval seconds. If no arguments are given to sa1 then a single record is written. The sa1 command is designed to be started automatically by the cron command. OPTIONS
--boot This option tells sa1 that the sadc command should be called without specifying the interval and count parameters in order to insert a dummy record, marking the time when the counters restarts from 0. EXAMPLE
To collect data (including those from disks) every 10 minutes, place the following entry in your root crontab file: 0,10,20,30,40,50 * * * * /usr/lib/sysstat/sa1 1 1 -S DISK Debian note The Debian sysstat package has already placed such an entry in your system crontab. Please refer to the /usr/share/doc/sys- stat/README.Debian file for details. FILES
/var/log/sysstat/sadd Indicate the daily data file, where the dd parameter is a number representing the day of the month. AUTHOR
Sebastien Godard (sysstat <at> orange.fr) SEE ALSO
sar(1), sadc(8), sa2(8), sadf(1), sysstat(5) http://pagesperso-orange.fr/sebastien.godard/ Linux FEBRUARY 2012 SA1(8)
All times are GMT -4. The time now is 01:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy