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!

parse file AND parse column with diff delimiter

Status
Not open for further replies.

AlbertAguirre

Programmer
Nov 21, 2001
273
US
Ok I need to parse a file but ALSO parse one of the columns in the file.

The file is delimited by | but the column I am parsing is delimited by '/'

Here is a sample record from the original file:

2008-08-28 23:08:36|218.165.182.133|image|78450882|/albums/rr29056/someusername/20080809/IMG_146701.jpg

My results must look like this:
2008-08-28 23:08:36|someusername

How do I accomplish this?


 
Hi

Code:
awk -F'[|/]' -vOFS='|' '{print $1,$8}' /input/file

[gray]# or ( gawk only )[/gray]

awk -F'|' -vOFS='|' '{split($5,a,"/");print $1,a[4]}' /input/file

[gray]# or[/gray]

awk -F'|' -vOFS='|' '{FS="/";split($5,a);FS="|";print $1,a[4]}' /input/file

Feherke.
 
Albert

Assuming your filename is list1

this should work for your example
Code:
cat list1 | tr "/" "|" | awk -F"|" '{print $1"|"$8}'
 
You could:

awk -F"|" '{split($NF,a,"/"); print $1"|"a[4]}' your_filename
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top