Simple Code to convert a field in the same file
Hi, I want to change/convert one field that is in a line of text(about 10 fields in a line) So in this line
'Mop-21050905','auth','info','info','26','2009-10-09 12:45:11','snort','snort[4574]: [1:408:5] ICMP Echo Reply [Classification: Misc activity] [Priority: 3]: {ICMP} 208.67.220.220 -> 95.224.96.106',8764647 I want to replace the datetime field '2009-10-09 12:45:11' with UTC '1255088707' e.g. 'Mop-21050905','auth','info','info','26','1255088707','snort','snort[4574]: [1:408:5] ICMP Echo Reply [Classification: Misc activity] [Priority: 3]: {ICMP} 208.67.220.220 -> 95.224.96.106',8764647 Would this command work? Also I would need to change multiple lines in the same way. sed -e 's/.*'//' | date -d "XXX" +%s filename I think these commands might do it but they are not correct Any suggestions? |
I ran a quick test with this.
First I wrote this script: Code:
#!/bin/sh Code:
$ ./bogus.sh Code:
cmd="sed 's/..... input.txt" Code:
cmd="sed -i 's/..... input.txt" |
Well I have a specific command to change the datetime to UTC, those integers I provided were an example of how it should be converted.
I think this code may work but needs some improvement filename | awk -F"/" '{ split($NF,tmp,"'"); print tmp[6] }' ` |
Quote:
the shell script. All you have to do is replace the line Code:
UTC=1255088707 Code:
UTC=$(your command here) |
Hi vonbiber, i am having trouble running the command
1st not sure how to run ./ bogus.sh, do u remove #!/bin/sh first 2nd think my date command is not been read properly, (maybe can't field to change)--> problem with "XXX" maybe 3rd you replace input.txt with your filename 4th i went to the bottom of my text document and copied the last line so the EOF would stop there This is what I ran #!/bin/sh ./ bogus.sh cat > filename <<EOF 'Mop-21050905','auth','info','info','26','2009-10-09 12:45:20','snort','snort[4574]: [1:2050:14] SQL version overflow attempt [Classification: Attempted Administrator Privilege Gain] [Priority: 1]: {UDP} 202.103.9.51:1096 -> 95.224.96.106:1434',8764657 EOF cat filename echo '-----------------' UTC=$(date -d "XXX" +%s) cmd="sed 's/[0-9]\{4,4\}-[0-9]\{2,2\}-[0-9]\{2,2\} [0-9]\{2,2\}:[0-9]\{2,2\}:[0- 9]\{2,2\}/$UTC/g' filename" eval "$cmd" Sorry I don't understand, it is difficult to make the changes when I can't understand some code :( |
bogus.sh is the name he made up for the test script he wrote; a replacement for yours.
|
If you have already a file to read from, copy and paste
the code below to a file that you name whatever you like (eg bogus.sh) and make executable (chmod +x bogus.sh) Code:
#!/bin/sh gave to your script shell and replace filename by the actual name of the file you're reading from) Code:
./bogus.sh filename Code:
UTC=$(date --utc +%s) It can be retrieved by invoking its value $UTC. Code:
cmd="sed ..." Code:
eval "$cmd" |
All times are GMT -5. The time now is 09:48 AM. |