0
sh -version
GNU sh, version 1.14.7(1)

cat file:

21/Oct/2013:21:29:29 +0530 10.104.x.x www.google.co.in http://www.google.co.in/ads/user-lists/998935479/?

I have a file with above pattern

grep -i http file | awk -F " " '{print $1","$3","$4","$5}'  > file2

with above command the output is below

21/Oct/2013:21:29:29,10.104.x.x,www.google.co.in,http://www.google.co.in/ads/user-lists/998935479/?

but I want output like below

21/Oct/2013,21:29:29,10.104.x.x,www.google.co.in,http://www.google.co.in/ads/user-lists/998935479/?

I want to split date and time in sap-rate values. please help me.

2
  • 1
    So, the only difference is the colon after 2013? Took me a while to find that... Commented Oct 24, 2013 at 10:22
  • yes, suppose to add one more column to sap rate date and time Commented Oct 24, 2013 at 10:24

3 Answers 3

1

Use sed:

grep -i http test.txt | awk -F " " '{print $1","$3","$4","$5}' | sed 's/:/,/'

This is very fragile because it assumes the first : needs to become a ,, but it seems that it will always be so, given your input.

Sign up to request clarification or add additional context in comments.

Comments

0

you don't need the grep|awk, if you have chosen awk, it can do all for you:

 awk -v OFS="," '/http/{sub(/:/,",",$1);print $1,$3,$4,$5}' file

Comments

0
sed -n "
/[hH][tT][tT][pP]/ {
   s/^\([^ ]\{1,\}\) [^ ]\{1,\} \(.*\)/\1,\2/p
   }" File

or

sed -n "
/[hH][tT][tT][pP]/ {
   s/ +[0-9]\{1,} /,/p
   }" File

you can replace /[hH][tT][tT][pP]/ with /${YourVariable}/ in this case, create the [aA] version of the variable content before in the shell

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.