Copy specific text from one file to another
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a text file that looks like this:
Start find in flight queries
2018-03-05 15:50:02,069:INFO:######################################
Start find completed queries
2018-03-05 15:50:02,070:INFO:Starting new HTTPS connection (1): server060
2018-03-05 15:50:02,083:DEBUG:"GET /queries?json HTTP/1.1" 401 0
2018-03-05 15:50:02,084:INFO:Resetting dropped connection: server060
2018-03-05 15:50:02,095:DEBUG:"GET /queries?json HTTP/1.1" 200 19059
2018-03-05 15:50:02,099:INFO:######################################
Start find in flight queries
The date and time changes every 5 minutes. I need to copy the very last date and time to another file. In this example its 2018-03-05 15:50:02.
Any suggestions are appreciated. I have used a little regex in the past but not good at it.
linux rhel regular-expression
add a comment |Â
up vote
1
down vote
favorite
I have a text file that looks like this:
Start find in flight queries
2018-03-05 15:50:02,069:INFO:######################################
Start find completed queries
2018-03-05 15:50:02,070:INFO:Starting new HTTPS connection (1): server060
2018-03-05 15:50:02,083:DEBUG:"GET /queries?json HTTP/1.1" 401 0
2018-03-05 15:50:02,084:INFO:Resetting dropped connection: server060
2018-03-05 15:50:02,095:DEBUG:"GET /queries?json HTTP/1.1" 200 19059
2018-03-05 15:50:02,099:INFO:######################################
Start find in flight queries
The date and time changes every 5 minutes. I need to copy the very last date and time to another file. In this example its 2018-03-05 15:50:02.
Any suggestions are appreciated. I have used a little regex in the past but not good at it.
linux rhel regular-expression
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a text file that looks like this:
Start find in flight queries
2018-03-05 15:50:02,069:INFO:######################################
Start find completed queries
2018-03-05 15:50:02,070:INFO:Starting new HTTPS connection (1): server060
2018-03-05 15:50:02,083:DEBUG:"GET /queries?json HTTP/1.1" 401 0
2018-03-05 15:50:02,084:INFO:Resetting dropped connection: server060
2018-03-05 15:50:02,095:DEBUG:"GET /queries?json HTTP/1.1" 200 19059
2018-03-05 15:50:02,099:INFO:######################################
Start find in flight queries
The date and time changes every 5 minutes. I need to copy the very last date and time to another file. In this example its 2018-03-05 15:50:02.
Any suggestions are appreciated. I have used a little regex in the past but not good at it.
linux rhel regular-expression
I have a text file that looks like this:
Start find in flight queries
2018-03-05 15:50:02,069:INFO:######################################
Start find completed queries
2018-03-05 15:50:02,070:INFO:Starting new HTTPS connection (1): server060
2018-03-05 15:50:02,083:DEBUG:"GET /queries?json HTTP/1.1" 401 0
2018-03-05 15:50:02,084:INFO:Resetting dropped connection: server060
2018-03-05 15:50:02,095:DEBUG:"GET /queries?json HTTP/1.1" 200 19059
2018-03-05 15:50:02,099:INFO:######################################
Start find in flight queries
The date and time changes every 5 minutes. I need to copy the very last date and time to another file. In this example its 2018-03-05 15:50:02.
Any suggestions are appreciated. I have used a little regex in the past but not good at it.
linux rhel regular-expression
edited Mar 5 at 21:14
asked Mar 5 at 21:00
user3508766
447
447
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
tac
+ grep
solution:
tac input.txt | grep -Eo -m1 '^[0-9]4(-[0-9]2)2 [0-9]2(:[0-9]2)2' > last_date.txt
1
excellent! Is there something you used to help you figuring this out so quickly?
â user3508766
Mar 5 at 21:10
@user3508766, yes, I use my mind )
â RomanPerekhrest
Mar 5 at 21:11
haha very good, spasibo bolshoe
â user3508766
Mar 5 at 21:12
@user3508766, you are welcome!
â RomanPerekhrest
Mar 5 at 21:14
add a comment |Â
up vote
1
down vote
Using awk without pipes ;)
awk -F'[ ,]' '
/^[0-9]4-[0-9]2-[0-9]2s+[0-9]2:[0-9]2:[0-9]2/
var=$1" "$2
ENDprint var
' file
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
tac
+ grep
solution:
tac input.txt | grep -Eo -m1 '^[0-9]4(-[0-9]2)2 [0-9]2(:[0-9]2)2' > last_date.txt
1
excellent! Is there something you used to help you figuring this out so quickly?
â user3508766
Mar 5 at 21:10
@user3508766, yes, I use my mind )
â RomanPerekhrest
Mar 5 at 21:11
haha very good, spasibo bolshoe
â user3508766
Mar 5 at 21:12
@user3508766, you are welcome!
â RomanPerekhrest
Mar 5 at 21:14
add a comment |Â
up vote
2
down vote
accepted
tac
+ grep
solution:
tac input.txt | grep -Eo -m1 '^[0-9]4(-[0-9]2)2 [0-9]2(:[0-9]2)2' > last_date.txt
1
excellent! Is there something you used to help you figuring this out so quickly?
â user3508766
Mar 5 at 21:10
@user3508766, yes, I use my mind )
â RomanPerekhrest
Mar 5 at 21:11
haha very good, spasibo bolshoe
â user3508766
Mar 5 at 21:12
@user3508766, you are welcome!
â RomanPerekhrest
Mar 5 at 21:14
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
tac
+ grep
solution:
tac input.txt | grep -Eo -m1 '^[0-9]4(-[0-9]2)2 [0-9]2(:[0-9]2)2' > last_date.txt
tac
+ grep
solution:
tac input.txt | grep -Eo -m1 '^[0-9]4(-[0-9]2)2 [0-9]2(:[0-9]2)2' > last_date.txt
answered Mar 5 at 21:06
RomanPerekhrest
22.4k12144
22.4k12144
1
excellent! Is there something you used to help you figuring this out so quickly?
â user3508766
Mar 5 at 21:10
@user3508766, yes, I use my mind )
â RomanPerekhrest
Mar 5 at 21:11
haha very good, spasibo bolshoe
â user3508766
Mar 5 at 21:12
@user3508766, you are welcome!
â RomanPerekhrest
Mar 5 at 21:14
add a comment |Â
1
excellent! Is there something you used to help you figuring this out so quickly?
â user3508766
Mar 5 at 21:10
@user3508766, yes, I use my mind )
â RomanPerekhrest
Mar 5 at 21:11
haha very good, spasibo bolshoe
â user3508766
Mar 5 at 21:12
@user3508766, you are welcome!
â RomanPerekhrest
Mar 5 at 21:14
1
1
excellent! Is there something you used to help you figuring this out so quickly?
â user3508766
Mar 5 at 21:10
excellent! Is there something you used to help you figuring this out so quickly?
â user3508766
Mar 5 at 21:10
@user3508766, yes, I use my mind )
â RomanPerekhrest
Mar 5 at 21:11
@user3508766, yes, I use my mind )
â RomanPerekhrest
Mar 5 at 21:11
haha very good, spasibo bolshoe
â user3508766
Mar 5 at 21:12
haha very good, spasibo bolshoe
â user3508766
Mar 5 at 21:12
@user3508766, you are welcome!
â RomanPerekhrest
Mar 5 at 21:14
@user3508766, you are welcome!
â RomanPerekhrest
Mar 5 at 21:14
add a comment |Â
up vote
1
down vote
Using awk without pipes ;)
awk -F'[ ,]' '
/^[0-9]4-[0-9]2-[0-9]2s+[0-9]2:[0-9]2:[0-9]2/
var=$1" "$2
ENDprint var
' file
add a comment |Â
up vote
1
down vote
Using awk without pipes ;)
awk -F'[ ,]' '
/^[0-9]4-[0-9]2-[0-9]2s+[0-9]2:[0-9]2:[0-9]2/
var=$1" "$2
ENDprint var
' file
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Using awk without pipes ;)
awk -F'[ ,]' '
/^[0-9]4-[0-9]2-[0-9]2s+[0-9]2:[0-9]2:[0-9]2/
var=$1" "$2
ENDprint var
' file
Using awk without pipes ;)
awk -F'[ ,]' '
/^[0-9]4-[0-9]2-[0-9]2s+[0-9]2:[0-9]2:[0-9]2/
var=$1" "$2
ENDprint var
' file
answered Mar 5 at 21:30
Gilles Quenot
15.3k13448
15.3k13448
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f428367%2fcopy-specific-text-from-one-file-to-another%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password