I'm trying to add a zero at the end of the data that start with 62018 (it will always start with 62018)

UNB+UNOA:1+5030917029608:14+5000119000006:14+070509:0850+620180001000200++INVOIC

any help would be appreciated.

Thank you
JG

Recommended Answers

All 3 Replies

sed -e 's/\+62018\([0-9]+\)\+\+/+62018\10++/' infile > outfile

sed -e 's/\+62018\([0-9]+\)\+\+/+62018\10++/' infile > outfile

it doesn't work at my side:

# sed -e 's/\+62018\([0-9]+\)\+\+/+62018\10++/' file
UNB+UNOA:1+5030917029608:14+5000119000006:14+070509:0850+62018000100020++INVOIC

@OP:try this

awk 'BEGIN{FS="+";OFS="+"}$6~/^62018/{ $6=$6"0"}{ print $0 }' file

it doesn't work at my side:

# sed -e 's/\+62018\([0-9]+\)\+\+/+62018\10++/' file
UNB+UNOA:1+5030917029608:14+5000119000006:14+070509:0850+62018000100020++INVOIC

@OP:try this

awk 'BEGIN{FS="+";OFS="+"}$6~/^62018/{ $6=$6"0"}{ print $0 }' file

Of course. "+" is only a valid regex character in perl. Sed doesn't recognize it as the "1 or more" function. So do like this instead:

# sed -e 's/+62018\([0-9]*\)++/+62018\10++/' infile > outfile
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.