LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-18-2005, 02:51 PM   #1
winchester169
Member
 
Registered: Mar 2004
Posts: 31

Rep: Reputation: 15
Editing/manipulating text files


What program(s) would I use to trim the first 5 char. from every line in a text file (line numbers are not wanted) and then to remove duplicate lines from teh same file???

Thank you!
 
Old 08-18-2005, 04:42 PM   #2
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
Code:
sed 's/^.....//' foo.txt | sort | uniq > bar.txt
Cheers,

mj
 
Old 08-18-2005, 06:32 PM   #3
winchester169
Member
 
Registered: Mar 2004
Posts: 31

Original Poster
Rep: Reputation: 15
Thank you

Worked perfectly

Why doesnt tha man page explaine all this?
 
Old 08-18-2005, 07:01 PM   #4
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
There won't be a single man page that will cover it, as what you want to do requires two operations (or three, as in the above version).

Sed is a powerful stream editor -- the man page only touches the surface of what it is capable of. The best thing to do is to google for Sed tutorials and how-to's, and have a play with it on you own system.

The other two parts are standard *nix commands. The 'uniq' utility does exactly what you think it should, i.e. remove successive duplicate lines from the input stream (see man uniq). For this to work, the input needs to be sorted, thus the 'sort' command.

Cheers,

mj
 
  


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
manipulating files tableyou Linux - Newbie 8 11-08-2005 03:38 AM
Editing text Files kool_kid Linux - Newbie 12 12-27-2004 12:21 AM
bash script on manipulating files fiomba Linux - Software 8 10-30-2004 09:31 PM
editing text files killertofu Linux - Newbie 2 10-15-2004 06:55 PM
Manipulating Files in vi Baldorg Linux - General 1 09-19-2003 08:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:31 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration