Replace files with thirst

0

Hello, I have a problem that I need to solve. I have a file that should be inserted exactly one column from another file, I am trying it as follows:

cat $1 | cut -d ',' -f2 | tr "/" "-" | awk -F "-" '{print $2"-"$1"-"$3}' > temp.txt

cat $1 | sed 's/[0-3][0-9]\/[0-1][0-9]\/[0-9][0-9][0-9][0-9]/temp.txt/'

Of which temp.txt is the file that has the updated column. The problem is that instead of replacing the specified column, it is replacing it with the filename "temp.txt". Any suggestions for fixing this? Or another way to do it? Thanks!

    
asked by anonymous 02.02.2017 / 14:54

2 answers

2

Although the question is very strange (hint for the future, it indicates what you want to do and not what you are doing because you may be following the wrong path), I assume you want to change the date field of the US format is totally illogical, but they are so). month / day / year, for day-month-year.

In this case, this will suffice:

cat $1 | sed -r 's,([0-9]{2})/([0-9]{2})/([0-9]{4}),--,g' 

"," are replacing usual "/" in sed, to avoid escaping "/" and -r to use extended regexp

    
02.02.2017 / 21:06
1

The solution proposed by @higuita is perfect (solves the problem at once).

However, by responding directly to your sub-question: put file in column 2 of a csv file, you can use the paste command:

paste -d, <(cut -d, -f1 a.csv ) coluna2.txt <(cut -d, -f3- a.csv)
  • paste - side by side
  • -d, - column separator ,
  • <(cut -d, -f1 a.csv ) - extract column 1 from the a.csv file
  • <(cut -d, -f3- a.csv) - extract columns 3 onwards
18.02.2017 / 14:15