LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-14-2017, 07:08 PM   #1
shellquery26666
LQ Newbie
 
Registered: Nov 2017
Posts: 2

Rep: Reputation: Disabled
Shell script urgent help please


Hello,

I have below string, even I have hundered of lines in a file. I want to exactly match last two consecutive strings.

2017-09-30|ACBD,TVF|01234|NULL|18|NULL|686091802|BANK OF ABCD, LIMITED, THE|2017-09-30 00:00:00

I want to extract the string "2017-09-30 00:00:00"

How can I do this please?

As date 2017-09-30 appears two times so I only want to search lines in a file which has string "2017-09-30 00:00:00"

Need urgent help please
 
Old 11-14-2017, 07:32 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,237

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
Did I miss something?

Code:
grep "2017-09-30 00:00:00" filename.txt
 
2 members found this post helpful.
Old 11-14-2017, 07:40 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,139

Rep: Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122
If the need for help is so urgent, next time show us what you attempted and why it didn't work for you. That way we can maybe help you better.
 
2 members found this post helpful.
Old 11-14-2017, 07:50 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Welcome to LQ!

Please see the Site FAQ for guidance in asking questions, and what supporting information to provide. It is always good practice to show what you have already tried and what the results were as well.

The title of your post should include the topic of your question to attract the most appropriate help from members. And please remember that everyone here volunteers their time and expertise, so asking for urgent help is not appropriate and may be considered rude by others.

The advice already given to use grep, or other regular expression search tool is the way to go. You can begin with grep, which is the basic Linux file search tool, see man grep for details. You may also find sed, awk and man regex helpful.

Give those a try and let us know how you progress. Good luck!

Last edited by astrogeek; 11-14-2017 at 07:51 PM. Reason: typo
 
1 members found this post helpful.
Old 11-15-2017, 01:18 PM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,733

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by dugan View Post
Did I miss something?

Code:
grep "2017-09-30 00:00:00" filename.txt
Or maybe
Code:
grep "2017-09-30 00:00:00$" filename.txt
or, if the time part is not fixed:
Code:
grep "2017-09-30.*$" filename.txt
That said, yes
Code:
man grep
and understand that the code we've shown you is going to return the whole line that matches, not just the pattern matched.
 
1 members found this post helpful.
Old 11-15-2017, 02:09 PM   #6
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 997

Rep: Reputation: 382Reputation: 382Reputation: 382Reputation: 382
OP seems to never have logged-in since posting

@shellquery26666:
The 'soft skill' of www-search is much faster and thus better
than posting 'basic' questions. Try a search like:
linux beginner tutorial man string match

Also try web-searching: "soft skills" for IT|ICT

Let us know IF you are serious about participating here at LQ.
Tell us a little about: your PC, distro, Linux experience/interest/goal.

Best wishes shellquery26666.
 
Old 11-23-2017, 01:10 PM   #7
shellquery26666
LQ Newbie
 
Registered: Nov 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by scasey View Post
Or maybe
Code:
grep "2017-09-30 00:00:00$" filename.txt
or, if the time part is not fixed:
Code:
grep "2017-09-30.*$" filename.txt
That said, yes
Code:
man grep
and understand that the code we've shown you is going to return the whole line that matches, not just the pattern matched.
Thanks a lot , it worked. Sorry was very busy , could not reply.

Many thanks guys for your time !!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent- shell script to create sub folders chetan_linux Programming 2 07-09-2012 04:35 PM
[SOLVED] URGENT : Display formatting on shell script arjundey Programming 5 10-09-2011 10:04 AM
URGENT: how can I log in to a remote system using a shell script!!! ahmad2080 Programming 5 07-08-2009 02:01 PM
URGENT----shell script to change word in file raghupal Programming 14 10-21-2008 12:49 AM
Urgent: Call a C program through Linux shell script nuwandee Programming 14 04-10-2004 07:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration