LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   N00b's bash, sed, or awk question (https://www.linuxquestions.org/questions/slackware-14/n00bs-bash-sed-or-awk-question-573530/)

petcherd 07-30-2007 07:38 PM

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.

wjevans_7d1@yahoo.co 07-30-2007 07:51 PM

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.

petcherd 07-30-2007 10:43 PM

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.

jlliagre 07-31-2007 12:09 AM

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/""'

mRgOBLIN 07-31-2007 02:44 AM

Code:

sed 's/^.\{,28\}//'
that will remove the first 28 characters for you

wjevans_7d1@yahoo.co 08-01-2007 06:42 AM

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\}//'


All times are GMT -5. The time now is 07:31 PM.