0

i have a file output.csv like this :

No | Timestamp | Table | agg | result | percentage | status | year | month | day
2022-09-30 00:00:00|2022-09-30 00:00:00|Source|count|287.472.321|-4.83%|Normal|2022|202209|20220930
2022-09-30 00:00:00|2022-09-30 00:00:00|Source|count|498.512.903|-4.05%|Normal|2022|202209|20220930
2022-09-30 00:00:00|2022-09-30 00:00:00|Source|count|19.089.222|-19.4%|Normal|2022|202209|20220930
2022-09-30 00:00:00|2022-09-30 00:00:00|Source|count|29.014.921|-2.47%|Normal|2022|202209|20220930
2022-09-30 00:00:00|2022-09-30 00:00:00|Source|count|148.770.415|-0.14%|Normal|2022|202209|20220930

all i wanna do is converting "." to blankspace in 5th column without affect on 6th column like this :

2022-09-30 00:00:00|2022-09-30 00:00:00|Source|count|287472321|-4.83%|Normal|2022|202209|20220930
2022-09-30 00:00:00|2022-09-30 00:00:00|Source|count|498512903|-4.05%|Normal|2022|202209|20220930
2022-09-30 00:00:00|2022-09-30 00:00:00|Source|count|19089222|-19.4%|Normal|2022|202209|20220930
2022-09-30 00:00:00|2022-09-30 00:00:00|Source|count|29014921|-2.47%|Normal|2022|202209|20220930
2022-09-30 00:00:00|2022-09-30 00:00:00|Source|count|148770415|-0.14%|Normal|2022|202209|20220930

i've tried using cat output.csv | grep -v -i "No " | sed 's/\.//g' > output3.csv But it will convert all columns that have "." .

So how to converting "." to blankspace in 5th column without affect on 6th column with still csv format output?

Thank you for the help!

1

2 Answers 2

1

It is easier to do this in awk:

awk 'BEGIN{ FS=OFS="|" } { gsub("[.]","",$5) } 1' file

But if you insist on using sed:

sed -e ':a' -e 's/^\(\([^|]*|\)\{4\}[^|]*\)\./\1/' -e 'ta' file
Sign up to request clarification or add additional context in comments.

4 Comments

can i ask you to detailing the script? i dont understand at : - BEGIN{ FS=OFS="|" } - "1" at the end Thank you
@cankcimen FS=OFS="|" sets both input and output field separators to |. 1 at the end prints the $0.
Ah i see, thank you. Can i ask 1 more thing, where can i learn more about this "sed" and "awk" function?
@cankcimenc Search for "GNU Awk User's Guide" and "GNU sed manual"
0

This might work for you (GNU sed and shell):

sed 'y/|/\n/;s/.*/echo "&"|sed "5s#\\.##g"/e;y/\n/|/' file

In essence, turn each line into a file and run a second invocation of sed where each address represents a column in the original line.

Translate |'s to newlines.

Write a mini sed invocation each time the pattern space is presented, that removes all .'s from the 5th line (each line in the invocation represents a column in the original line).

Translate newlines back to |'s.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.