|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
awk to remove last two -*-*
Code:
fq-bar-something-1.0-r1.src.rpm ----> fq-bar-something fq-bar-xx-r1-rel.src.rpm ---------> fq-bar-xx fq-bar-ff-ver-11-rel.src.rpm -------> fq-bar-ff-ver any help? |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Code:
cat filename | awk -F '-' '{$NF=""; $(NF-1)=""; print }' | sed 's/ /-/g' | sed 's/--$//g'Please next time seperate input and expected output in two different CODEQOUTE Last edited by fuad_; 01-05-2013 at 12:38 AM.. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
That doesn't get what I want. please see my expected ouput |
|
#4
|
|||
|
|||
|
Code:
cat filename | awk -F '-' '{$NF=""; $(NF-1)=""; print }' | sed 's/ /-/g' | sed 's/--$//g'Please next time seperate input and expected output in two different CODEQOUTE |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Try: Code:
awk 'NF-=2{$1=$1}1' FS=- OFS=- fileCode:
sed 's/-[^-]*-[^-]*$//' file |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
I had wanted to offer sth like Code:
$ awk -F '-' '{for (i=1;i<NF-2;i++) printf "%s-", $i; printf "%s\n", $(i) }' filebut scutinizer's proposals beat them all! |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| can I remove the first char using AWK? | Abdulelah | Shell Programming and Scripting | 2 | 01-03-2011 05:18 PM |
| AWK remove string in between () | jimmy_y | Shell Programming and Scripting | 3 | 05-19-2010 04:08 AM |
| a SED/AWK way to remove everything except... | necron | Shell Programming and Scripting | 4 | 03-25-2010 08:13 PM |
| Remove prefix using awk | pinnacle | Shell Programming and Scripting | 5 | 06-02-2009 04:53 AM |
| How to remove ^Z (eof) using sub in awk | placroix1 | Shell Programming and Scripting | 2 | 05-13-2005 10:40 AM |
|
|