Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep file paths in each line of text 2

Status
Not open for further replies.

RVSachin

Technical User
Nov 12, 2001
77
IN
Hi,

My text file contains something like following:

Code:
adsdfaddfd <some path1>
adlfjakflafaf /<some path2>
adfabzlhzxhledfdfe3dfstet  <some path3>
d3dfstet  <some other path>

How do I print or redirect only the path information to another file?
That is, each line in second file should contain all the file paths found in file1

If possible, please include a note explaining the commands in your reply.

Thanks,

RV
 
Code:
sed 's/^[^ ]* //g' infile > outfile

Do you know sed?
It's an non-interactive stream-editor, which performs commands on input (optional: files, here 'infile') and prints to stdout, here redirected to outfile.

One of its commands is 's'=substitute.
s/pattern/replace/g
here we replace with nothing - ergo: we delete.
.../g: globally, not only once.

the pattern is encapsulated between slashes:
/^[^ ]* /
which means: ^ from beginning of line
[^ ] every character, which is not a space
* multiple times.


seeking a job as java-programmer in Berlin:
 
Or something like this ?
awk '{print $NF}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

Thanks for the solution.
Can you please let me know how this works?..I mean, what does NF do?

Thanks,

Ravi
 
In awk, NF is a builtin variable holding the number of fields of the current record and so, $NF is the last field.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top