【发布时间】:2020-12-21 06:44:42
【问题描述】:
我研究了很多,最后决定提出这个问题。我正在使用 Informatica Pre Session 命令读取与特定模式匹配的文件并删除这些文件中的所有“”字符。 同样,一旦完成,我需要删除最后一行。
在个别文件上,我可以使用以下方法:
#To remove Double Quotes from the file
sed -i -e 's/\"//g' /opt/informed/file_name_20200801.txt
# This works for individual files but next I'm trying to loop through a directory
#with matching file names and delete quotes in all files in the directory
for file in opt/informed/file_name_*.txt; do
sed 's/\"//g' "$file" >> /opt/informed/"$file";
done;
#It runs without error but nothing happens. I want to edit the existing files to get rid of
#any double quotes in those files. ```
#Once I'm able to achieve that, I can apply a similar loop to process the files
#to delete last #line of each file using:
sed -e '$d' /opt/informed/filename.txt >> filename.txt #Works for individual Files
【问题讨论】:
-
您正在寻找
-i选项的sed工具。在单个文件上尝试此操作,然后您也可以在多个文件上运行此操作sed -i 's/\"//g' Input_file这将删除所有出现的"并将更改保存到 Input_file 本身。 -
那么 for 循环是否正确?只需将 -i 放在 sed 前面并为多个文件运行 for 循环命令就可以了?
标签: shell unix etl informatica informatica-powercenter