Akimbot
Akimbot

Reputation: 1

How to extract a specific number sequence in a file

Hi i wanted to ask for help regarding on how to create a shell script that reads a file then extracts values from it then outputs it in a file

here is the content of the file:

some.ip.address,,0530,,,**134148.117132,134148.117176,134148.117693,134148.117712**,,,,,,134148.114552,,,,,0000016972,172.28.61.176,,,443,192.168.5.208,,,109,0,0,0,0,0,92,14,0,0,0,0,,,,200,,,text/html,,GET ?fname=111.txt&seqnum=0000016972 HTTP/1.1
some.ip.address,,0530,,,134118.111838,134118.111881,134118.112469,134118.112488,,,,,,134118.109233,,,,,0000016912,172.28.61.176,,,443,192.168.5.208,,,109,0,0,0,0,0,92,14,0,0,0,0,,,,200,,,text/html,,GET ?fname=111.txt&seqnum=0000016912 HTTP/1.1
some.ip.address,,0530,,,134148.120441,134148.120471,134148.120955,134148.120973,,,,,,134148.117845,,,,,0000016973,172.28.61.176,,,443,192.168.5.208,,,109,0,0,0,0,0,92,14,0,0,0,0,,,,200,,,text/html,,GET ?fname=111.txt&seqnum=0000016973 HTTP/1.1
some.ip.address,,0530,,,134118.114515,134118.114559,134118.115044,134118.115061,,,,,,134118.111938,,,,,0000016913,172.28.61.176,,,443,192.168.5.208,,,109,0,0,0,0,0,92,14,0,0,0,0,,,,200,,,text/html,,GET ?fname=111.txt&seqnum=0000016913 HTTP/1.1
some.ip.address,,0530,,,134149.117256,134149.117324,134149.117916,134149.117935,,,,,,134149.114722,,,,,0000016974,172.28.61.176,,,443,192.168.5.208,,,109,0,0,0,0,0,92,14,0,0,0,0,,,,200,,,text/html,,GET ?fname=111.txt&seqnum=0000016974 HTTP/1.1
some.ip.address,,0530,,,134119.111996,134119.112040,134119.112663,134119.112682,,,,,,134119.109432,,,,,0000016914,172.28.61.176,,,443,192.168.5.208,,,109,0,0,0,0,0,92,14,0,0,0,0,,,,200,,,text/html,,GET ?fname=111.txt&seqnum=0000016914 HTTP/1.1
some.ip.address,,0530,,,134149.120156,134149.120186,134149.120691,134149.120709,,,,,,134149.117374,,,,,0000016975,172.28.61.176,,,443,192.168.5.208,,,109,0,0,0,0,0,92,14,0,0,0,0,,,,200,,,text/html,,GET ?fname=111.txt&seqnum=0000016975 HTTP/1.1

now i need to extract the values in bold and out put it in a csv file need help !!

Upvotes: 0

Views: 51

Answers (2)

user3239835
user3239835

Reputation: 75

you can use cut also

syntax like,

while read line 
do

echo $line | cut -f <required fields> -d "," >> newfile.csv

done < inputfile

syntax is not perfect but will do.

Upvotes: 1

Mark Setchell
Mark Setchell

Reputation: 207748

Like this with awk:

awk -F, '{printf "%s,%s,%s,%s\n",$6,$7,$8,$9}' file > newfile.csv

That -F, sets the field separator to a comma and it then extracts the 6th through 9th field on each line.

Upvotes: 0

Related Questions