![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to export | jisha | BSD | 4 | 01-21-2008 04:06 AM |
| combining fields in two text fields | shocker | Shell Programming and Scripting | 3 | 01-16-2008 08:27 AM |
| export??? | Justinkase | Shell Programming and Scripting | 1 | 12-03-2007 03:32 PM |
| difference between set and export | shriashishpatil | UNIX for Dummies Questions & Answers | 1 | 02-22-2006 10:28 AM |
| export variables | srishan | Shell Programming and Scripting | 4 | 07-06-2004 09:53 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
export only last two fields?
export only last two fields?
here is my test file, with variable length of fields, each line is composed of letter only, and each line has at least 2 fields, fields were separated by dot (.) abcd.abc.mlm dft.dfasdf.bmk.kdjlka ksdfalksdjfsl.tyu.ml kasdjf.asdfkja.asdfj.asdf.df.m lja.ml aslkjdfjasldkf.sadlfkasdjlf.sdfasdfsa.asdfasdf.fdlm I am trying to use sed to parse the test file, and only display the last two fields, like abc.mlm bmk.kdjlka tyu.ml df.m At first my idea was something like ++ sed 's/!\.[a-z][a-z]*\.[a-z][a-z]*$/&/' test ++, and sure it did not work. Any help? thank you! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
fields.txt:
Code:
abcd.abc.mlm dft.dfasdf.bmk.kdjlka ksdfalksdjfsl.tyu.ml kasdjf.asdfkja.asdfj.asdf.df.m lja.ml aslkjdfjasldkf.sadlfkasdjlf.sdfasdfsa.asdfasdf.fdlm Code:
awk 'BEGIN { FS="."; OFS="." } { print $(NF-1),$NF }' fields.txt
Code:
abc.mlm bmk.kdjlka tyu.ml df.m lja.ml asdfasdf.fdlm |
|
#3
|
|||
|
|||
|
Really cool and thanks Glenn Arndt!
But still I have great interest in whether sed can do this I think "pattern keeping method" should work, as following sed 's/^.*\(\.[a-z][a-z]*\.[a-z][a-z]*$\)/\1/' but apparently it does not. I am reading more sed help file trying to figure out why. |
|
#4
|
||||
|
||||
|
Code:
echo 'dft.dfasdf.bmk.kdjlka' | sed 's/.*[.]\(.*\)[.]\(.*\)/\1.\2/' |
|
#5
|
|||
|
|||
|
Thank you vgersh99!
|
|||
| Google The UNIX and Linux Forums |