|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Geeting only required Data
I have a file:
gk@dev1:~> cat more.txt iam :here home/usr/bin iam :here home/usr iam :here help/home/bin iam :here home/bin/var i want to cut the some of the letters from the above file and print only the last letters like my data would be bin usr bin var How do i do that? any one ..need help? |
|
#2
|
||||
|
||||
|
The easiest way is probably to replace all of the / with white space then print the last column.
Code:
sed -e 's/\// /g' test.txt | awk '{print $NF}'
|
|
#3
|
|||
|
|||
|
No need to change the delimiter, just specify it:
Code:
awk '{FS="/";print $NF}' file
|
|
#4
|
||||
|
||||
|
Quote:
I decided against that, because the file does not necessarily have to contain a /. i.e. Code:
iam :here home/usr/bin iam :here help/home/bin iam :here home |
|
#5
|
|||
|
|||
|
Quote:
Parsing of strings/text is very easy, in Python. Code:
>>> for lines in open("more.txt"):
... os.path.split(lines.split()[-1])[-1]
...
'bin'
'bin'
'home'
|
|
#6
|
|||
|
|||
|
Very interesting, but not the output I woudl have expected - should it not have returned:
Code:
bin usr bin var from that input file? |
|
#7
|
|||
|
|||
|
Quote:
I had a different input file for testing, and pasted the wrong output. Code:
>>> for lines in open("more.txt"):
... print os.path.split(lines.split()[-1])[-1]
...
bin
usr
bin
var
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Geeting only required Data |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|