Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have file wich has many lines inside

All lines that contain

file=/aaaaaaa/bbbbbbb/cccccc/dddddd.txt

it needs to be stripped to this format

file=/dddddd.txt

i am executing perl in bash somethin like this

perl -i -pe 'regex' /localpath/file.txt

In perl command above in 'regex' i would need command to do it, how to do it ?

share|improve this question

closed as off topic by John Gardeniers, EightBitTony, Ward, mdpc, voretaq7 Dec 4 '12 at 17:12

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
General unix questions like this (not specifically related to system administration) should be asked on Unix & Linux (or Stack Overflow if they're basic programming) - this kind of "gimmeh teh c0dez" question isn't really on-topic for Server Fault. –  voretaq7 Dec 4 '12 at 17:12

3 Answers 3

If you just want to extract the file, I would use File::Basename

share|improve this answer
perl -n -e 'print $1.$2."\n"if (/(.+\=)\/.+\/.+\/.+(\/.+)$/)' /localpath/file.txt > newfile.txt

Theres probably more elegant ways to do it.

share|improve this answer
 perl -ne '/(.*=).*\/(.*)$/ && print "$1/$2\n"' /localpath/file
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.