Print particular string in a field of csv file - part 2

Hi, all

I need your help and suggestions.
I want to print particular strings in a field of a csv file and show them in terminal. Here is an example of the csv file.

SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw
/home/intannf/nu/2015_0313_090651_219.JPG,0.,-7.77223,110.37310,30.75,996.46,148.75,180.94,182.00,63.92
/home/intannf/up/folder/new/IMAG0399.JPG,1.14,-7.78805,110.37457,30.53,997.44,139.93,186.60,175.61,184.11
/home/intannf/me/DSC122.jpg,0.80,-7.78805,110.37457,30.64,998.83,127.60,171.19,227.02,7.66

Output required

2015_0313_090651_219.JPG
IMAG0399.JPG
DSC122.jpg

When i tried to print them using this code:

awk -F "[/,]" 'NR>1 {print $5}' $file

I get the wrong result like this:

2015_0313_090651_219.JPG
new
0.80

because it just print the fifth column, and each of them has different column.
Would you mind to help me to solve it? I really need your help. Thanks in advance.

Regards,
Intan

Try

awk -F, 'NR>1 {sub(/.*\//,"", $1); print $1}' file2
2015_0313_090651_219.JPG
IMAG0399.JPG
DSC122.jpg
1 Like

Hi RudiC,

thanks for your help!
But i don't know yet about this code

sub(/.*\//,"", $1)

Would you mind to tell me about it? Thanks in advance

From GNU awk manual:

Hi balajesuri,
I am still getting confused about this code. What does it mean?

/.*\//,""

Unless you don't have gawk
read file ; drop first line ; print everything before first , ; print last field after /

cat inputfile | tail +2 | awk -F,  '{ print $1}'  | awk -F/  '{ print $NF}'
1 Like

It means replace the longest string of characters ( .* ) that ends with a / ( \/ ) and replace it with nothing ( "" ), i.e. delete it...

The other two slashes are used to demarcate the extended regular expression .*\/

1 Like

Hi, garydeena thanks for your suggestion and Scrutinizer thanks for your explanation! It's so helpful!