LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-30-2007, 07:38 PM   #1
petcherd
Member
 
Registered: Dec 2006
Location: Portland, OR - USA
Distribution: Formerly Slackware; now RH, SuSE, Debian/Ubuntu, & Asianux
Posts: 55

Rep: Reputation: 15
N00b's bash, sed, or awk question


I'm trying to compare two huge directory trees that start like this:

/backup/volume/20070718/tree/...

and

/backup/volume/20070719/tree/...

diff doesn't work for me because it sees that difference in the dates, and considers every line different.

How can I trim-off the first 28 characters of each line of a text file?

I had considered using sed to substitute "/backup/volume/20070718/tree/" with "/", but I got messed-up with the / characters.
 
Old 07-30-2007, 07:51 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Code:
sed -e 's/^............................//' input_file > output_file
#          1234567890123456789012345678
#                   1111111111222222222
If you're sure you don't want the first 28 characters, this will get rid of 'em no matter what they are. The only hitch is that any line which contains fewer than 28 characters will be left alone.

Hope this helps.
 
Old 07-30-2007, 10:43 PM   #3
petcherd
Member
 
Registered: Dec 2006
Location: Portland, OR - USA
Distribution: Formerly Slackware; now RH, SuSE, Debian/Ubuntu, & Asianux
Posts: 55

Original Poster
Rep: Reputation: 15
No, that's perfect for me! I am certain that I have no lines shorter than 28 characters. I'm going to run back to my server's shell and give it a try right now....

It works just right.

Last edited by petcherd; 07-30-2007 at 11:11 PM.
 
Old 07-31-2007, 12:09 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by petcherd
I had considered using sed to substitute "/backup/volume/20070718/tree/" with "/", but I got messed-up with the / characters.
Here is one way to overcome the / issue with sed:
Code:
sed 's"/backup/volume/20070719/tree/""'
 
Old 07-31-2007, 02:44 AM   #5
mRgOBLIN
Slackware Contributor
 
Registered: Jun 2002
Location: New Zealand
Distribution: Slackware
Posts: 999

Rep: Reputation: 231Reputation: 231Reputation: 231
Code:
sed 's/^.\{,28\}//'
that will remove the first 28 characters for you
 
Old 08-01-2007, 06:42 AM   #6
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
For some versions of sed, this will give you a syntax error:

Code:
sed 's/^.\{,28\}//'
If that happens, be more explicit:

Code:
sed 's/^.\{0,28\}//'
 
  


Reply

Tags
sed



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
I have a question about awk or sed sqp1982 Programming 9 03-28-2006 05:37 AM
Difficult sed/awk question 3saul Linux - Software 2 03-04-2006 02:49 AM
Replacing a place holder on a template with bash, sed, and or awk rignes Programming 7 02-16-2006 04:20 PM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
How to loop or sort in bash, awk or sed? j4r0d Programming 1 09-09-2004 03:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:20 PM.

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