Mallik
Mallik

Reputation: 709

how to get some particular words from a line using cut command

I have a file with the following text

and I want to get the 1st,2nd,and 4th value only**1343311371204**,*****210*****,http://172.16.1.139/CC_WEB/jsp/Login.jsp,**200**,OK,true,9,9 1343311371044,304,http://172.16.1.139/CC_WEB/jsp/Login.jsp,200,OK,true,8,8 1343311371109,239,http://172.16.1.139/CC_WEB/jsp/Login.jsp,200,OK,true,8,8 1343311371083,263,http://172.16.1.139/CC_WEB/jsp/Login.jsp,200,OK,true,8,8 in every line. So How can I do it?

Upvotes: 0

Views: 5237

Answers (2)

Christophe Drevet
Christophe Drevet

Reputation: 945

Using cut

cut -d, -f1,2,4 your_file should do it fine.

Using read (bash builtin function)

Using read in a while loop, you can use variables to do things with those values :

while IFS=',' read timestamp value2 url code remains ; do
    # use those variables
done < your_file`

Upvotes: 3

Vijay
Vijay

Reputation: 67231

awk -F, '{print $1,$2,$4}' your_file

Upvotes: 1

Related Questions