Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wanna check if 2 lines have equal $4 my shell must check if the diffrence between $3 in line 2 and $2 in line 3 is equal 1 it must concatenate both line into one like this




I dont know even to use awk or something else

share|improve this question
Can you explain better what you want? This is totally unclear: "I wanna check if 2 lines have equal $4 my shell must check..." – Radu Rădeanu Dec 10 '13 at 8:04
if there exist any 2 lines in my file having equal $4 (for example 3 in the above file line 2 and 3 have equal values ) I need to Concatenate them to something like the output – Mina Dec 10 '13 at 8:21
What about doing simply sort -t';' -k4 -u file? – user54813 Dec 10 '13 at 8:41
up vote 3 down vote accepted

Perl to the rescue:

perl -F';' -lane '
    if ($L[2] + 1 == $F[1] and $L[3] == $F[3]) {
        $L[2] = $F[2]
    } else {
        print join ";", @L if @L;
        @L = @F
    END { print join ";", @L }
' file.csv
share|improve this answer
Please if i want to add another field at the beggining this filed is i which represent index and increments every line ?? – Mina Dec 10 '13 at 10:17
@Mina: ++$i increments the variable $i and returns its new value. Insert it as the second parameter to each print join. – choroba Dec 10 '13 at 14:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.