LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-07-2017, 01:03 PM   #1
iceman81
Member
 
Registered: Jan 2013
Location: New Jersey
Distribution: CentOS, Arch
Posts: 181

Rep: Reputation: Disabled
trimming text files with sed


example text
Code:
007 - Agent Under Fire (USA).7z                                       13-Sep-2015 08:25     1.0G
007 - Everything or Nothing (USA).7z                                  13-Sep-2015 08:44     870.9M
007 - From Russia with Love (USA).7z                                  13-Sep-2015 08:49     1.1G
007 - Nightfire (USA).7z                                              13-Sep-2015 08:41     1.1G
1080 Avalanche (USA).7z                                               13-Sep-2015 08:39     827.5M
18 Wheeler - American Pro Trucker (USA).7z                            13-Sep-2015 08:37     1.2G
2002 FIFA World Cup (USA).7z                                          13-Sep-2015 08:42     1.1G
2006 FIFA World Cup (USA).7z                                          13-Sep-2015 08:48     1.0G
4x4 Evo 2 (USA).7z                                                    13-Sep-2015 08:47     1.0G
i basically have a large file of around 577 lines, that i'd like to trim everything after "(USA)"

would sed achieve this?

im thinking i would have to make the string start with a '.' then wildcard until the 'G' , then maybe do another for 'M'
 
Old 08-07-2017, 01:10 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,694
Blog Entries: 4

Rep: Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943
Yes, it can. The pattern is a close-parenthesis followed by an arbitrary span of a set of anything that is not a close-parenthesis until the end of the line.


Try some variations. See [ ], *, and $ in particular.

http://www.grymoire.com/Unix/Regular.html
http://www.regular-expressions.info/quickstart.html
 
Old 08-07-2017, 01:19 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,805

Rep: Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224
Piece of cake:
Code:
sed 's/(USA).*/(USA)/'
Replace the string "(USA)" and anything that follows with just "(USA)".
 
2 members found this post helpful.
Old 08-07-2017, 01:58 PM   #4
iceman81
Member
 
Registered: Jan 2013
Location: New Jersey
Distribution: CentOS, Arch
Posts: 181

Original Poster
Rep: Reputation: Disabled
that worked, thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
sed or awk to repair temperatures in text files Woodsman Programming 2 09-05-2011 08:34 PM
using awk or sed to process text files tuxlux Programming 29 08-24-2011 12:38 AM
Replacing text in files without using sed dfresh4130 Programming 16 05-28-2009 11:13 AM
Modify a text files with awk/sed/perl climber75 Programming 15 08-05-2008 04:35 PM
sed with large text files? apollyonus Linux - Server 3 03-22-2007 08:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:53 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