sed throwing sed: -e expression #(number), char (number): unknown command: `(letter)'

Venkatesh

I wrote a shell script which reads some files and copy all the data from these files to other consolidated file.

This happens multiple times and previously copied data will not be copied again. For this i am saving the last copied line in a separate file and comparing it from the second time.

Flow of logic :

  • For the first time, read individual files and copy the whole data except last line into the consolidated file. Saving the last copied line into a temporary file.

sed '$d' $file >> $consolidatedCSVFile

tail -2 $file | head -1 > $consolidatedCSVFile$lastLines/$(basename $file)$lastLine

  • From second time, read last line from the temporary file and search for that line in individual file. When found, take all the lines from the next line and append to consolidated file.

Full script:

#!/bin/bash

consolidatedCSVFile=$1
endTime=$2

curdate=$(date +%s)

CSVFiles=${@:3}
CSVFiles=${CSVFiles[@]}

lastLines=_LASTLINES
lastLine=_LASTLINE

newMerge=false

# Returns 1 if Consolidated file is empty
[ -s $consolidatedCSVFile  ]
if [ $? == 1  ]
    then
        mkdir $consolidatedCSVFile$lastLines
        newMerge=true
fi

testInProcess=false

if [ $endTime -ge $curdate  ]
    then
        testInProcess=true
fi

for file in $CSVFiles
do
if $newMerge ;
    then
        touch $consolidatedCSVFile$1astLines5(basename $file)$lastLine
        sed $d $file >> $consolidatedCSVFile
        tail -2 $file | head -1 >   $consolidatedCSVFile$1astLines5(basename $file)$lastLine
    else
        availableLastLine="`cat $consolidatedCSVFile$1astLines/$(basename $file)$lastLine`"
        if $testInProcess
            then
                sed '1,/^'"$availableLastLine"'$/d' $file | sed '$d' >> $consolidatedCSVFile
                tail -2 $file | head -1 > $consolidatedCSVFile$1astLines5(basename $file)$lastLine
            else
                sed '1,/^'"$availableLastLine"'$/d' $file >> $consolidatedCSVFile
        fi
fi

done

if  !  $testInProcess ;
then
    rm -rf $consolidatedCSVFile$lastLines
fi

Sometimes, i get error as sed: -e expression #1, char 26: unknown command: 'X'

My guess

I am trying to combine the files generated by JMeter. Sometimes, the files are generating data like 1439459065780,5,SOAP/XML-RPC Request,200,OK,ws test 1-3,text,true,267,3,3,5

I think the problem is while sed '1,/^'"$availableLastLine"'$/d' $file | sed '$d' >> $consolidatedCSVFile at SOAP/XML. Slash(/) could be problem here.

Venkatesh

worked after modifying availableLastLine to availableLastLine=$(sed 's/\//\\\//' $consolidatedCSVFile$lastLines/$(basename $file)$lastLine).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

sed throwing sed: -e expression #(number), char (number): unknown command: `(letter)'

From Dev

sed: -e expression #1, char 4: unknown command:

From Dev

sed: -e expression #1, char 1: unknown command: `''

From Dev

sed: -e expression #1, char 1: unknown command: '|'

From Dev

bash sed: -e expression #1, char 21: number option to `s' command may not be zero

From Dev

`sed: -e expression #1, char 4: unknown command:` but the line endings are fine

From Dev

sed: -e expression #1, char 23: unknown option to `s'

From Dev

/bin/sed: -e expression #1, char 56: unknown option to `s'

From Dev

sed: -e expression #3, char 59: unknown option to `s'

From Dev

bash - sed: -e expression #1, char 15: unterminated `s' command

From Dev

sed: -e expression #1, char 35: unterminated `s' command

From Dev

sed: -e expression #1, char 37: unterminated `s' command

From Dev

sed: -e expression #1, char 10: missing command

From Dev

sed: -e expression #1, char 10: extra characters after command

From Dev

sed: -e expression #1, char XX: unterminated `s' command

From Dev

sed: -e expression #1, char 5: unterminated `s' command

From Dev

sed Error sed: -e expression #1, char 7: unterminated `s' command

From Dev

replace a string containing an unknown number with sed

From Dev

sed: -e expression #1, char 3: unexpected `,'

From Dev

sed command to delete variable number of lines

From Dev

sed command that replaces number and word by two

From Dev

sed command with regular expression

From Dev

sed unknown command on windows cmd

From Dev

sed unknown command on windows cmd

From Dev

sed in bash script: unknown command: `''`

From Dev

sed: -e expression #1, char 44: unterminated address regex

From Dev

Decreasing a number with sed

From Dev

extracting a number in a line with sed

From Dev

Check whether a char is a letter or a number?

Related Related

  1. 1

    sed throwing sed: -e expression #(number), char (number): unknown command: `(letter)'

  2. 2

    sed: -e expression #1, char 4: unknown command:

  3. 3

    sed: -e expression #1, char 1: unknown command: `''

  4. 4

    sed: -e expression #1, char 1: unknown command: '|'

  5. 5

    bash sed: -e expression #1, char 21: number option to `s' command may not be zero

  6. 6

    `sed: -e expression #1, char 4: unknown command:` but the line endings are fine

  7. 7

    sed: -e expression #1, char 23: unknown option to `s'

  8. 8

    /bin/sed: -e expression #1, char 56: unknown option to `s'

  9. 9

    sed: -e expression #3, char 59: unknown option to `s'

  10. 10

    bash - sed: -e expression #1, char 15: unterminated `s' command

  11. 11

    sed: -e expression #1, char 35: unterminated `s' command

  12. 12

    sed: -e expression #1, char 37: unterminated `s' command

  13. 13

    sed: -e expression #1, char 10: missing command

  14. 14

    sed: -e expression #1, char 10: extra characters after command

  15. 15

    sed: -e expression #1, char XX: unterminated `s' command

  16. 16

    sed: -e expression #1, char 5: unterminated `s' command

  17. 17

    sed Error sed: -e expression #1, char 7: unterminated `s' command

  18. 18

    replace a string containing an unknown number with sed

  19. 19

    sed: -e expression #1, char 3: unexpected `,'

  20. 20

    sed command to delete variable number of lines

  21. 21

    sed command that replaces number and word by two

  22. 22

    sed command with regular expression

  23. 23

    sed unknown command on windows cmd

  24. 24

    sed unknown command on windows cmd

  25. 25

    sed in bash script: unknown command: `''`

  26. 26

    sed: -e expression #1, char 44: unterminated address regex

  27. 27

    Decreasing a number with sed

  28. 28

    extracting a number in a line with sed

  29. 29

    Check whether a char is a letter or a number?

HotTag

Archive