Hello experts,
I have 2 files
file1:
lalalala good file
file2:
lblblblb good file
these two files are the same in my test case, how can I start compare after certain number of characters? or is there a better way to do this?
Thank you
Hello experts,
I have 2 files
file1:
lalalala good file
file2:
lblblblb good file
these two files are the same in my test case, how can I start compare after certain number of characters? or is there a better way to do this?
Thank you
Are the files all in one line?
You ask about comparing files after a certain number of characters, so are you looking to ignore a fixed number characters on each line for each file?
If those are the 'true' files, then a solution could be proposed.
However, if there is more to the samples, it would be helpful to see.
The files contain more than 1 line, a more likely example would be:
file1:
lalalala good file
lalblala good file
lalalalb good file
lalalbla good file
file2:
lblblblb good file
lblblclb good file
lblclblb good file
lclblblb good file
compare:
#file1 and file2 are the same
so I want to start compare after say 8 characters on every line in the two files.
I created two sample files (note I purposefully made a difference in the 2nd file calling something bad instead of good - to see some output from a diff command)
> cat tfile1
lalalala good file
lalblala good file
lalalalb good file
lalalbla good file
> cat tfile2
lblblblb good file
lblblclb good file
lblclblb good file
lclblblb bad file
then, using the following script:
> cat cfile
#! /bin/bash
f1="tfile1"
f2="tfile2"
f1out=$f1".out"
f2out=$f2".out"
cat tfile1 | cut -c10- >$f1out
cat tfile2 | cut -c10- >$f2out
diff $f1out $f2out
results in:
> cfile
4c4
< good file
---
> bad file
Sorry, can't express enough of my thanks~~~~~~
I was stuck on it for so long.
THANK YOU
one interesting thing is using "cat tfile1 | cut -c10- >$f1out "
tfile1 and f1out must be different.
is there any way to replace the same file?
what about "sed"?