sed or revelent command to remove car


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed or revelent command to remove car
# 1  
Old 05-28-2018
sed or revelent command to remove car

How to remove the digits. I need to check after / if I have more the 3 digit remove all including backslash


Input file

Code:
  portshow 8/150800
  portshow 9/150900
  portshow 12/150c00
  portshow 12/150 
   portshow 15/150f00
  portshow 16/151000
  portshow 17/151100
  portshow 17/15
 portshow 19/151300
  portshow 22/151600
  portshow 23/151700
  portshow 24/151800
  portshow 27/151b00
  portshow 28/151c00
  portshow 29/151d00
  portshow 31/151f00
  portshow 33/152100
  portshow 34/152200
  portshow 37/152500
  portshow 38/152600
  portshow 39/152700
  portshow 40/152800
  portshow 41/152900
  portshow 42/152a00
  portshow 43/152b00
  portshow 47/152f00
  portshow 48/153000
  portshow 49/153100
  portshow 50/153200
  portshow 51/153300
  portshow 52/153400
  portshow 53/153500
  portshow 54/153600
  portshow 55/153700
  exit

Output required

Code:
portshow 8
portshow 9
portshow 12
portshow 12/150
portshow 15
portshow 16
portshow 17
portshow 17/15
portshow 19
portshow 22
portshow 23
portshow 24
portshow 27
portshow 28
portshow 29
portshow 31
portshow 33
portshow 34
portshow 37
portshow 38
portshow 39
portshow 40
portshow 41
portshow 42
portshow 43
portshow 47
portshow 48
portshow 49
portshow 50
portshow 51
portshow 52
portshow 53
portshow 54
portshow 55
exit


Last edited by ranjancom2000; 05-28-2018 at 12:33 PM..
# 2  
Old 05-28-2018
Any attempts / ideas / thoughts from your side?


EDIT: So four and more digits should be removed? Your sample unfortunately doesn't give examples which data to keep. What if there's alpha or punct chars in there?
# 3  
Old 05-28-2018
Quote:
Originally Posted by RudiC
Any attempts / ideas / thoughts from your side?


EDIT: So four and more digits should be removed? Your sample unfortunately doesn't give examples which data to keep. What if there's alpha or punct chars in there?

i have edit the input file. I need to keep after backslash it has up to 3 digit. If it is more then digit i need remove all including the backslash
# 4  
Old 05-28-2018
I think you mean slash not backslash.
Match 4 or more non-blanks after a slash, and substitute all this with nothing:
Code:
sed 's#/[^ ]\{4,\}##'

This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 05-28-2018
Quote:
Originally Posted by MadeInGermany
I think you mean slash not backslash.
Match 4 or more non-blanks after a slash, and substitute all this with nothing:
Code:
sed 's#/[^ ]\{4,\}##'

Thanks it is working great. Yes i mean to say slash.

So this sed command remove all character if it has more the 4 right after slash
# 6  
Old 05-28-2018
Hello ranjancom2000,

Following awk may help you on same and it will ONLY look for digits after / if they are more than 3 it will remove everything after /.

Code:
awk --re-interval -F"/" '{val=$NF;gsub(/[a-zA-Z]*| +$/,"",val)} length(val)>3{print $1;next} 1'  Input_file

Let me know if this helps you.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 7  
Old 05-29-2018
Thanks for the replay i was using the solution provided by MadeInGermany
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to remove a word from string

Hello All, I am running a command find . -name amp.cfg | cut -c 3- which gives me output something like below rel/prod/amp.cfg rel/fld/amp.cfg deb/detail/amp.cfg deb/err/amp.cfg I want to remove trailing "/amp.cfg" so that i should get output something like... (7 Replies)
Discussion started by: anand.shah
7 Replies

2. Shell Programming and Scripting

how to remove a variable starting with dot using sed command

Hi, I want to remove a variable starting with dot(.) in a file using sed command. aaa sss .abc s/^\.abc/d I tried this but it didnt worked. (5 Replies)
Discussion started by: vdhingra123
5 Replies

3. UNIX for Dummies Questions & Answers

Using sed command to remove multiple instances of repeating headers in one file?

Hi, I have catenated multiple output files (from a monte carlo run) into one big output file. Each individual file has it's own two line header. So when I catenate, there are multiple two line headers (of the same wording) within the big file. How do I use the sed command to search for the... (1 Reply)
Discussion started by: rebazon
1 Replies

4. Shell Programming and Scripting

sed command to remove the first field from a '|' delimited file

Hi I have a file with fields delimited by |. I need to remove the first field from the file. I tried cut but it just extracts that field. sample.output abc|100|name1 cde|200|name2 efg|300|name3 Output should be sample.output 100|name1 200|name2 300|name3 thanks Var (6 Replies)
Discussion started by: var285
6 Replies

5. Shell Programming and Scripting

Remove comma from decimal value using sed command

Hi Experts , My requirement is like this .. I have source comming as 4,234.55 I need and out put = 4234.55 I need to write a sed command .. I have already used sed command for multiple conditions in a file for replacing comma , double quotes , brackets , retain negative values..... (3 Replies)
Discussion started by: bshivali
3 Replies

6. Shell Programming and Scripting

remove newline between two string with sed command in unix shellscript

I have a file (test.dat) which contains data like this 459|199811047|a |b |shan kar|ooty| 460|199811047|a |bv |gur u|cbe| but I need it like: 459|199811047|a |b |shankar|ooty| 460|199811047|a |b |guru|cbe| While reading the data from this file, I don't want to remove newline from the end of... (4 Replies)
Discussion started by: jcrshankar
4 Replies

7. Shell Programming and Scripting

sed remove multiple set of lines in one command

is there a way with sed to removed more than one set of lines in one line? so i mean sed ${firstElem},${lastIndex}d web.xml > web1.xml this will delete lines between ${firstElem},${lastIndex} i want in the same line to do somethinkg like this (doesn't work so far) sed... (3 Replies)
Discussion started by: Poki
3 Replies

8. UNIX for Dummies Questions & Answers

sed command to remove characters help!

I am trying to analyse a large file of sequencing data, example of first 10 lines below, @HWUSI-EAS656_0044_FC:7:1:2447:1039#GCAATT/1 GNCTATGGCTTGCCGGGCTCAGGGAAGACAATCATAGCCATGAAAATCATGGAAAAGATCAGAAAAACATTTCAA +HWUSI-EAS656_0044_FC:7:1:2447:1039#GCAATT/1... (1 Reply)
Discussion started by: Adeleh
1 Replies

9. Shell Programming and Scripting

Command to remove duplicate lines with perl,sed,awk

Input: hello hello hello hello monkey donkey hello hello drink dance drink Output should be: hello hello monkey donkey drink dance (9 Replies)
Discussion started by: cola
9 Replies

10. Shell Programming and Scripting

What's the command to remove empty lines with sed?

3 10 20 10 100 100 10000 Output: 3 10 20 10 100 100 10000 ---------- Post updated at 07:59 AM ---------- Previous update was at 07:56 AM ---------- sed '/^$/d' file doesn't work. (8 Replies)
Discussion started by: cola
8 Replies
Login or Register to Ask a Question